home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 8 / Power CD-ROM 8.iso / os2 / fb_189a / source / filebar.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-21  |  248.3 KB  |  5,424 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. //                                FileBar
  4. //
  5. //         OS/2 Application Launch Facility and WPS Shell Replacement
  6. //
  7. //                         Written By Eric A. Wolf
  8. //                 Copyright (C) 1994 - All Rights Reserved
  9. //
  10. // This source code may be used for reference ONLY!  It is provided AS-IS and no
  11. // guarantees are made as to its utility, functionality or correctness.  It is
  12. // provided solely as a guide to aid aspiring OS/2 2.x Presentation Manager
  13. // programmers in developing their own PM applications.  No modifications are
  14. // to be made to this code for re-release as a same or different product.  This
  15. // code must be distributed (in its original entirety) with the executable
  16. // portion of this product.
  17. //
  18. //          -- Please register this shareware product for $10 today --
  19. //                          See documentation for details
  20. //
  21. // Project Start Date:      December 26, 1993
  22. // Project Completion Date: January   3, 1994
  23. //
  24. // Written using Borland C++ for OS/2, version 1.0, Borland Resource Workshop,
  25. //               and the IBM OS/2 2.1 bitmap/icon editor
  26. //
  27. // File Last Modified:      November 22, 1994
  28. //
  29. ////////////////////////////////////////////////////////////////////////////////
  30.  
  31.  
  32. ////////////////////////////////////////////////////////////////////////////////
  33. // set compile-time flags for what os/2 header information should be included
  34. ////////////////////////////////////////////////////////////////////////////////
  35. #define INCL_PM
  36. #define INCL_DOSSESMGR
  37. #define INCL_DOSERRORS
  38. #define INCL_DOSMISC
  39. #define INCL_WINPOINTERS
  40. #define INCL_WINPROGRAMLIST
  41. #define INCL_WINWORKPLACE
  42. #define INCL_DOSPROCESS
  43.  
  44. ////////////////////////////////////////////////////////////////////////////////
  45. // include C, C++, OS/2, application and resource header files
  46. ////////////////////////////////////////////////////////////////////////////////
  47. #include <stdio.h>
  48. #include <stdlib.h>
  49. #include <ctype.h>
  50. #include <string.h>
  51. #include <time.h>
  52. #include "options.h"
  53. #ifdef GERMAN
  54.     #include "german.h"
  55. #else
  56.     #include "english.h"
  57. #endif
  58. #include "dll/filebar.h"                      // include DLL function prototypes
  59.  
  60. ////////////////////////////////////////////////////////////////////////////////
  61. // MakeHourglassPointer - macro to make the mouse pointer the hourglass
  62. ////////////////////////////////////////////////////////////////////////////////
  63. #define MakeHourglassPointer() {                                                               \
  64.                                  HPOINTER pointer;                                             \
  65.                                  pointer = WinQuerySysPointer( HWND_DESKTOP, SPTR_WAIT, FALSE);\
  66.                                  WinSetPointer( HWND_DESKTOP, pointer );                       \
  67.                                }
  68.  
  69.  
  70. ////////////////////////////////////////////////////////////////////////////////
  71. // MakeArrowPointer - macro to make the mouse pointer the arrow
  72. ////////////////////////////////////////////////////////////////////////////////
  73. #define MakeArrowPointer() {                                                                \
  74.                              HPOINTER pointer;                                              \
  75.                              pointer = WinQuerySysPointer( HWND_DESKTOP, SPTR_ARROW, FALSE);\
  76.                              WinSetPointer( HWND_DESKTOP, pointer );                        \
  77.                            }
  78.  
  79.  
  80. ////////////////////////////////////////////////////////////////////////////////
  81. // define application constants
  82. ////////////////////////////////////////////////////////////////////////////////
  83. #define PASSWORDLEN           8
  84. #define NO                    'N'
  85. #define YES                   'Y'
  86. #define DEFAULTPASSWORD       "FILEBAR\0"
  87. #define MAXCOUNT              100
  88. #define TEMPSTRING            64
  89. #define AT_TOP                TRUE
  90. #define AT_BOTTOM             FALSE
  91. #define TIMERID               1
  92. #define MAXTASKS              30
  93. #define MAXMENUS              8
  94. #define MAXITEMS              40
  95. #define MAXPATH               CCHMAXPATH
  96. #define MAXACTIONSTRINGLENGTH MAXPATH
  97. #define MAXITEMNAMELENGTH     24
  98. #define MAXMENUNAMELENGTH     20
  99. #define MAXARGSTRINGLENGTH    80
  100. #define MAXDIRSTRINGLENGTH    MAXPATH
  101. #define WINDOWED              1
  102. #define FULLSCREEN            2
  103. #define PM                    4
  104. #define DOS                   8
  105. #define OS2                   16
  106. #define WINOS2                32
  107. #define STARTMIN              64
  108. #define STARTMAX              128
  109. #define WPSFOLDER             256
  110. #define STARTASWPS            512
  111. #define SCALED                128
  112. #define TILED                 64
  113. #define OS2SHELL              "CMD.EXE"
  114. #define OPTIONFILE            "FILEBAR.INI"
  115. #define LAUNCHFILE            "STARTPRG.CMD"
  116. #define LAUNCHINPUTS          "/C STARTPRG.CMD"
  117. #define SEPARATOR             "────────────────────────"
  118. #define WPSDESKTOPNAME        "Desktop"
  119. #define FILEBARMENUON         "~FileBar"
  120. #define FILEBARMENUOFF        "\x04"
  121. #define STARTINPUT            '['
  122. #define ENDINPUT              ']'
  123. #define BITMAPNAME            "\\FILEBAR.BMP\0"
  124. #define CHIMESOUNDFILE        "\\CHIME.WAV\0"
  125. #define NOCOLOR               1
  126. #define MAXSTARTITEMS         10
  127. #define WPSBUFFER             3084
  128. #define MAXALARMS             48
  129. #define SCHEDULE_EVERYHOUR    1
  130. #define SCHEDULE_EVERYDAY     2
  131. #define SCHEDULE_EVERYWEEK    4
  132. #define SCHEDULE_EVERYMONTH   8
  133. #define SCHEDULE_EVERYYEAR    16
  134. #define SCHEDULE_USEWAVFILE   32
  135. #define SCHEDULE_SOUNDONLY    64
  136. #define SCHEDULE_LAUNCHAPP    128
  137. #define BOOLEAN               INT
  138. #define LAUNCHED              0
  139. #define TERMCHAR              250
  140. #define TASKMENUON            MSG71
  141. #define TASKMENUOFF           MSG72
  142.  
  143.  
  144. ////////////////////////////////////////////////////////////////////////////////
  145. // writeString - writes a string out with quotes on either side
  146. ////////////////////////////////////////////////////////////////////////////////
  147. #define writeString(stream, string) fprintf(stream, "%c%s%c\n", TERMCHAR, string, TERMCHAR)
  148.  
  149.  
  150. ////////////////////////////////////////////////////////////////////////////////
  151. // define function prototypes
  152. ////////////////////////////////////////////////////////////////////////////////
  153. VOID validateTimeEntry( VOID );
  154. VOID sortTimeEntries( INT );
  155. VOID displayBackground( VOID );
  156. VOID resizeMenu( VOID );
  157. VOID readOptionFile( VOID );
  158. VOID writeOptionFile( VOID );
  159. VOID readString( FILE*, CHAR* );
  160. VOID restartTimer( VOID );
  161. VOID displayTimeDate( VOID );
  162. VOID SwapTwoMenus( SHORT, SHORT );
  163. VOID SwapTwoItems( SHORT, SHORT, SHORT );
  164. VOID updateItemList( HWND );
  165. VOID updateEditItemData( HWND hWnd );
  166. VOID updateEditItemData( HWND hWnd );
  167. VOID ExecuteStartUpList( VOID );
  168. VOID updateCalendar( HWND );
  169. VOID ringChime( CHAR* );
  170. VOID checkAlarms( SHORT, SHORT, SHORT, SHORT, SHORT );
  171. VOID updateTimeDisplay( HWND );
  172. VOID reviseScheduledItem( INT );
  173. VOID resetFileDialog( VOID );
  174. VOID changePassword( CHAR* );
  175. BYTE numberOfDaysInMonth( INT, INT );
  176. SHORT startApplication( SHORT, SHORT );
  177. MRESULT EXPENTRY ClientWndProc( HWND, ULONG, MPARAM, MPARAM );
  178. MRESULT EXPENTRY GenericProc( HWND, ULONG, MPARAM, MPARAM );
  179. MRESULT EXPENTRY TimeDateProc( HWND, ULONG, MPARAM, MPARAM );
  180. MRESULT EXPENTRY EditMenuProc( HWND, ULONG, MPARAM, MPARAM );
  181. MRESULT EXPENTRY AddAMenuProc( HWND, ULONG, MPARAM, MPARAM );
  182. MRESULT EXPENTRY EditItemProc( HWND, ULONG, MPARAM, MPARAM );
  183. MRESULT EXPENTRY EditItemDataProc( HWND, ULONG, MPARAM, MPARAM );
  184. MRESULT EXPENTRY AddAnItemProc( HWND, ULONG, MPARAM, MPARAM );
  185. MRESULT EXPENTRY menuHandler( HWND, ULONG, MPARAM, MPARAM );
  186. MRESULT EXPENTRY EnterParamProc( HWND, ULONG, MPARAM, MPARAM );
  187. MRESULT EXPENTRY backgroundProc( HWND, ULONG, MPARAM, MPARAM );
  188. MRESULT EXPENTRY startupProc( HWND, ULONG, MPARAM, MPARAM );
  189. MRESULT EXPENTRY schedulerProc( HWND, ULONG, MPARAM, MPARAM );
  190. MRESULT EXPENTRY scheduleProc( HWND, ULONG, MPARAM, MPARAM );
  191. MRESULT EXPENTRY reminderNoteProc( HWND, ULONG, MPARAM, MPARAM );
  192. MRESULT EXPENTRY itemProc( HWND, ULONG, MPARAM, MPARAM );
  193. MRESULT EXPENTRY showAllItemsProc( HWND, ULONG, MPARAM, MPARAM );
  194. MRESULT EXPENTRY LaunchItemProc( HWND, ULONG, MPARAM, MPARAM );
  195. MRESULT EXPENTRY popUpOptionsProc( HWND, ULONG, MPARAM, MPARAM );
  196. MRESULT EXPENTRY globalPasswordProc( HWND, ULONG, MPARAM, MPARAM );
  197.  
  198. extern "C" {
  199.     #define INCL_REXXSAA
  200.     #include "rexxsaa.h"
  201.     RexxStart rexxStart;
  202.     }
  203.  
  204.  
  205. ////////////////////////////////////////////////////////////////////////////////
  206. // define alarm/task scheduler item structure
  207. ////////////////////////////////////////////////////////////////////////////////
  208. struct ALARMS {
  209.     BYTE  AlarmYear;
  210.     BYTE  AlarmMonth;
  211.     BYTE  AlarmDay;
  212.     BYTE  AlarmHour;
  213.     BYTE  AlarmMinute;
  214.     BYTE  options;
  215.     CHAR  ReminderWAV[MAXACTIONSTRINGLENGTH];
  216.     CHAR  ActionToDo[MAXACTIONSTRINGLENGTH];
  217. };
  218.  
  219.  
  220. ////////////////////////////////////////////////////////////////////////////////
  221. // define menu item structure
  222. ////////////////////////////////////////////////////////////////////////////////
  223. struct USERMENUITEM {
  224.     CHAR     ItemName[MAXITEMNAMELENGTH];
  225.     CHAR     ActionToDo[MAXACTIONSTRINGLENGTH];
  226.     CHAR     Directory[MAXDIRSTRINGLENGTH];
  227.     CHAR     CmdLnArgs[MAXARGSTRINGLENGTH];
  228.     SHORT    ProgType;
  229.     CHAR     Password[PASSWORDLEN + 1];
  230.     CHAR     PasswordEnabled;
  231. };
  232.  
  233.  
  234. ////////////////////////////////////////////////////////////////////////////////
  235. // define global variables
  236. ////////////////////////////////////////////////////////////////////////////////
  237. const         BYTE daysInMonth[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
  238. USERMENUITEM* Menus[MAXMENUS][MAXITEMS];
  239. ALARMS*       alarmPtr[MAXALARMS];
  240. HAB      hab;
  241. HMQ      hmq;
  242. PID      TaskId[MAXTASKS];
  243. PFNWP    menuMessageHandler;
  244. FILEDLG  fileDlgInfo;
  245. MENUITEM menuData[MAXMENUS];
  246. LONG     oldNumItems;
  247. LONG     ScreenSizeX   = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN) + 2;
  248. LONG     ScreenSizeY   = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  249. LONG     MenuHeight    = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2;
  250. LONG     sysMenuHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2;
  251. ULONG    popUpMessageID = WM_CHORD;
  252. ULONG    noteTimerNumber;
  253. ULONG    timerNumber;
  254. ULONG    timeOption = TIMEANDDATE;
  255. USHORT   year;
  256. SHORT    startDay;
  257. SHORT    ItemSelection;
  258. SHORT    MenuSelection;
  259. SHORT    oldProgType;
  260. HWND     hwndWPS;
  261. HWND     hwndDesktop;
  262. HWND     hwndClient;
  263. HWND     hwndFrame;
  264. HWND     hwndMenu;
  265. HWND     TaskHandle[MAXTASKS];
  266. HWND     popUpMenu = 0;
  267. HWND     oldTaskHandles[MAXTASKS];
  268. CHAR     password[PASSWORDLEN + 1];
  269. CHAR     oldPassword[PASSWORDLEN + 1];
  270. CHAR     globalProtection = NO;
  271. CHAR     oldPasswordEnabled;
  272. CHAR     stringTerminator = '\0';
  273. CHAR     MenuName[MAXMENUS][MAXMENUNAMELENGTH];
  274. CHAR     backgroundBitmap[MAXACTIONSTRINGLENGTH];
  275. CHAR     hourlyChimeWavFile[MAXACTIONSTRINGLENGTH];
  276. CHAR     variableText[MAXARGSTRINGLENGTH-2];
  277. CHAR     oldItemName[MAXITEMNAMELENGTH];
  278. CHAR     oldDirectory[MAXACTIONSTRINGLENGTH];
  279. CHAR     oldAction[MAXACTIONSTRINGLENGTH];
  280. CHAR     oldCmdLn[MAXARGSTRINGLENGTH];
  281. CHAR     parameterTitle[MAXITEMNAMELENGTH+8];
  282. CHAR     tmpBuffer[MAXPATH*2];
  283. INT      backgroundAttr = 3 + TILED;
  284. INT      numAlarms = 0;
  285. INT      numberOfAlarms;
  286. INT      repeatTime = 60;
  287. INT      EditItem;
  288. INT      NumMenus;
  289. INT      taskItemSelected;
  290. INT      numStartItems = 0;
  291. INT      StartUpMenu[MAXSTARTITEMS];
  292. INT      StartUpItem[MAXSTARTITEMS];
  293. INT      day;
  294. INT      month;
  295. PCHAR    ParameterTextPtr;
  296. PCHAR    currentReminderWavFile;
  297. BOOLEAN  RunningWarp = FALSE;
  298. BOOLEAN  alreadyChimed = FALSE;
  299. BOOLEAN  BarPosition = AT_TOP;
  300. BOOLEAN  HourlyChime = TRUE;
  301. BOOLEAN  FileBarMenuOn = TRUE;
  302. BOOLEAN  timeSync;
  303. BOOLEAN  checkBeforeDelete = TRUE;
  304. BOOLEAN  showBackground = FALSE;
  305. BOOLEAN  isBackgroundDisplayed = FALSE;
  306. BOOLEAN  startUp = TRUE;
  307. BOOLEAN  DoStartUpList = FALSE;
  308. BOOLEAN  allowPopUpMenu = TRUE;
  309. BOOLEAN  maximizeDesktop = FALSE;
  310. BOOLEAN  interceptMsg = TRUE;
  311. BOOLEAN  hideFileBar = FALSE;
  312. BOOLEAN  noJump = TRUE;
  313. BYTE     NumItems[MAXMENUS];
  314. BOOL     FileBarIsShell = FALSE;
  315.  
  316.  
  317. ////////////////////////////////////////////////////////////////////////////////
  318. // main function - application entry point
  319. ////////////////////////////////////////////////////////////////////////////////
  320. main( int argc, char* argv[] )
  321. {
  322.     PSZ buffer;
  323.     struct tm *time_now;
  324.     ULONG FrameFlags;
  325.     time_t currentTime;
  326.     hab = WinInitialize(0);                   // handle: anchor block
  327.     hmq = WinCreateMsgQueue(hab, 0);          // handle: message queue
  328.     CHAR ClassName[] = "FileBar";             // store a name for our class
  329.     MENUITEM menuItem;                        // used to modify menu data
  330.  
  331.     //--------------------------------------------------------------------------
  332.     // register the window class
  333.     //--------------------------------------------------------------------------
  334.     WinRegisterClass(hab,
  335.                      ClassName,      // name of class being registered
  336.                      ClientWndProc,  // window procedure for class
  337.                      0,              // class style
  338.                      0);             // extra memory to reserve
  339.  
  340.     //--------------------------------------------------------------------------
  341.     // create a window with a menu bar added on.  Note that the menu bar could
  342.     // be defined in the WinCreateStdWindow call (set the resource id equal= to
  343.     // MENUBAR) but is not since I need a handle to the menu (so I can later
  344.     // modify the menu).  Thus, WinLoadMenu is used following WinCreateStdWindow
  345.     //--------------------------------------------------------------------------
  346.     FrameFlags = FCF_AUTOICON|FCF_TASKLIST|FCF_BORDER|FCF_MENU;
  347.     hwndFrame = WinCreateStdWindow(HWND_DESKTOP,       // parent
  348.                                         WS_VISIBLE,    // style
  349.                                         &FrameFlags,   // control data
  350.                                         ClassName,     // client name
  351.                                         ClassName,     // title bar text
  352.                                         0,             // client style
  353.                                         NULLHANDLE,    // resource handle
  354.                                         MENUBAR,       // resource id
  355.                                         &hwndClient);  // client pointer
  356.  
  357.     //--------------------------------------------------------------------------
  358.     // move and size application to span entire top of desktop
  359.     //--------------------------------------------------------------------------
  360.     WinSetWindowPos( hwndFrame, (HWND)0, 0, (ScreenSizeY-MenuHeight),
  361.                      ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE|SWP_MINIMIZE);
  362.     WinEnableWindowUpdate( hwndFrame, FALSE);
  363.  
  364.     hwndMenu = WinWindowFromID( hwndFrame, FID_MENU );
  365.     MakeHourglassPointer ();                  // switch to hourglass cursor
  366.                                               // during initialization
  367.  
  368.     //--------------------------------------------------------------------------
  369.     // perform basic initialization
  370.     //--------------------------------------------------------------------------
  371.     NumMenus = 0;
  372.     MenuSelection = 100;
  373.  
  374.     for ( short k = 0; k < MAXMENUS; k++ ) {
  375.         WinSendMsg( hwndMenu, MM_QUERYITEM, MPFROM2SHORT(100*(k+1),TRUE),
  376.                     MPFROMP(&menuData[k]));
  377.         menuItem = menuData[k];
  378.         menuItem.afStyle = MIS_STATIC;
  379.         menuItem.afAttribute = MIA_DISABLED;
  380.         menuItem.hwndSubMenu = (HWND)0;
  381.         WinSendMsg( hwndMenu, MM_SETITEM, MPFROM2SHORT(100*(k+1),TRUE),
  382.                     MPFROMP(&menuItem));
  383.         WinSetMenuItemText( hwndMenu, 100*(k+1), "");
  384.         NumItems[ k ] = 0;
  385.         }
  386.  
  387.     memset( &fileDlgInfo, 0, sizeof(FILEDLG));
  388.     fileDlgInfo.cbSize = sizeof(fileDlgInfo);
  389.     menuMessageHandler = WinSubclassWindow( hwndMenu, menuHandler );
  390.  
  391.     //--------------------------------------------------------------------------
  392.     // change to directory that application executable is started from
  393.     //--------------------------------------------------------------------------
  394.     if (argc > 0) {
  395.         strncpy( tmpBuffer, argv[0], sizeof(tmpBuffer) );
  396.         if (tmpBuffer[1]==':')
  397.             DosSetDefaultDisk( (ULONG)(toupper(tmpBuffer[0])-'A' + 1) );
  398.  
  399.         k = strlen(tmpBuffer);
  400.         while ((tmpBuffer[k]!='\\') && (k>0))
  401.            k--;
  402.  
  403.         if (k) {
  404.             tmpBuffer[k]='\0';
  405.             if (DosSetCurrentDir( tmpBuffer )!=0) {
  406.                 char mesg[]=MSG2;
  407.                 WinMessageBox( HWND_DESKTOP, hwndFrame, mesg, tmpBuffer, 0,
  408.                                MB_MOVEABLE|MB_ERROR|MB_OK);
  409.                 }
  410.             }
  411.         strcpy( backgroundBitmap, tmpBuffer );
  412.         strcat( backgroundBitmap, BITMAPNAME );
  413.         strcpy( hourlyChimeWavFile, tmpBuffer );
  414.         strcat( hourlyChimeWavFile, CHIMESOUNDFILE );
  415.         }
  416.  
  417.  
  418.     //--------------------------------------------------------------------------
  419.     // if user has passed us a second argument, it is path to settings file
  420.     //--------------------------------------------------------------------------
  421.     //if (argc > 1) {
  422.     //    settingsPath = new CHAR[MAXPATH];
  423.     //    strncpy( settingsPath, argv[1], MAXPATH );
  424.     //}
  425.  
  426.     //--------------------------------------------------------------------------
  427.     // find out if user is running Warp v3.0
  428.     //--------------------------------------------------------------------------
  429.     {
  430.     UCHAR buffer[2];
  431.     char buf[128];
  432.  
  433.     DosQuerySysInfo( QSV_VERSION_MAJOR, QSV_VERSION_MINOR, buffer, 2 );
  434.     if ((buffer[0]==100) && (buffer[1]==191))
  435.         RunningWarp = TRUE;
  436.     }
  437.  
  438.     //--------------------------------------------------------------------------
  439.     // record time and date for scheduler program
  440.     //--------------------------------------------------------------------------
  441.     tzset();
  442.     time(¤tTime);
  443.     time_now = localtime( ¤tTime );
  444.     month = time_now->tm_mon;
  445.     year = time_now->tm_year;
  446.  
  447.  
  448.     //--------------------------------------------------------------------------
  449.     //--------------------------------------------------------------------------
  450.     {
  451.     UCHAR ucClass[8];
  452.     HENUM henumWindows;
  453.  
  454.     hwndDesktop=WinQueryWindow(HWND_DESKTOP, QW_BOTTOM);
  455.     henumWindows=WinBeginEnumWindows(hwndDesktop);
  456.     while (hwndWPS=WinGetNextWindow(henumWindows)) {
  457.         WinQueryClassName(hwndWPS, sizeof(ucClass), (PCH)ucClass);
  458.         if(!strcmp(ucClass, DESKTOP_CLASS)) break;
  459.         }
  460.     WinEndEnumWindows(henumWindows);
  461.     hwndDesktop=WinQueryDesktopWindow(hab, NULLHANDLE);
  462.     }
  463.  
  464.     //--------------------------------------------------------------------------
  465.     // read in the user option file and set up the menu bar appropriately
  466.     // check the user time/date option and put it on the menu bar
  467.     // reset our timer in case they want the current time displayed
  468.     //--------------------------------------------------------------------------
  469.     readOptionFile();                         // read in option file
  470.  
  471.     //--------------------------------------------------------------------------
  472.     // decide if FileBar is replacement shell or not
  473.     //--------------------------------------------------------------------------
  474.     k=0;
  475.     DosScanEnv( "RUNWORKPLACE", &buffer);
  476.     while (buffer[k]!=0) {
  477.         if ((buffer[k]=='F') || (buffer[k]=='f'))
  478.             if (strnicmp(&buffer[k],"filebar",7)==0) {
  479.                 SWCNTRL swctl;
  480.                 HSWITCH sw = WinQuerySwitchHandle( hwndFrame, 0 );
  481.  
  482.                 FileBarIsShell = TRUE;
  483.                 // if user wants, make switch entry for FileBar "disappear"!
  484.                 WinQuerySwitchEntry( sw, &swctl );
  485.                 swctl.fbJump        = SWL_NOTJUMPABLE;
  486.                 swctl.uchVisibility = SWL_INVISIBLE;
  487.                 if (noJump)
  488.                     WinChangeSwitchEntry( sw, &swctl );
  489.                 }
  490.         k++;
  491.         }
  492.  
  493.     sortTimeEntries( numAlarms );             // sort the alarm entries
  494.     restartTimer();                           // resync our clock
  495.     updateTimeDisplay( hwndMenu );            // display current date/time
  496.  
  497.     // make FileBar visible
  498.     WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_RESTORE);
  499.  
  500.     if ((!FileBarIsShell) && (maximizeDesktop) && (BarPosition==AT_TOP)) {
  501.         ULONG numItems;
  502.         ULONG Buffer;
  503.         PSWBLOCK SwitchBlockPtr;
  504.  
  505.         // get the # of items and the switch list from the system
  506.         numItems = WinQuerySwitchList( hab, NULL, 0 );
  507.         Buffer = (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
  508.         PVOID my = new BYTE[Buffer];
  509.         WinQuerySwitchList( hab, (SWBLOCK*)my, Buffer );
  510.         SwitchBlockPtr = (PSWBLOCK)(my);
  511.  
  512.         for (k = 0; k < numItems; k++ )
  513.             if (strcmp(SwitchBlockPtr->aswentry[k].swctl.szSwtitle,
  514.                                                          WPSDESKTOPNAME) == 0) {
  515.                 WinSetWindowPos( SwitchBlockPtr->aswentry[k].swctl.hwnd,
  516.                                  (HWND)0, 0, 0, 0, 0, SWP_MAXIMIZE);
  517.                 WinSetWindowPos( SwitchBlockPtr->aswentry[k].swctl.hwnd,
  518.                                  (HWND)0, 0, 0, ScreenSizeX,
  519.                                  ScreenSizeY-MenuHeight+sysMenuHeight+1,
  520.                                  SWP_MOVE|SWP_SIZE);
  521.                 }
  522.         }
  523.  
  524.  
  525.     displayBackground();                      // restore user background bitmap
  526.     ExecuteStartUpList();                     // start execution list
  527.     MakeArrowPointer ();                      // switch back to arrow pointer,
  528.  
  529.     WinSetParent( hwndFrame, HWND_DESKTOP, FALSE );
  530.     WinSetFocus( HWND_DESKTOP, hwndFrame );
  531.  
  532.     //--------------------------------------------------------------------------
  533.     // initialize our DLL so that we intercept window sizing messages and hide
  534.     // the bar if we need to do so
  535.     //--------------------------------------------------------------------------
  536.     FileBarInit( hwndFrame );
  537.     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight,
  538.                       (interceptMsg==TRUE), allowPopUpMenu, popUpMessageID );
  539.     WinEnableWindowUpdate( hwndFrame, TRUE);
  540.     WinInvalidateRegion( hwndFrame, NULL, FALSE );
  541.  
  542.     if (hideFileBar)
  543.         WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_HIDE);
  544.  
  545.     //--------------------------------------------------------------------------
  546.     // create a message queue and then as long as there are messages to get,
  547.     // get them and dispatch them to our message handlers
  548.     //--------------------------------------------------------------------------
  549.     {
  550.         QMSG qmsg;                                     // create a message queue
  551.  
  552.         while( WinGetMsg( hab, &qmsg, (HWND)0, 0, 0 ) !=FALSE )
  553.             WinDispatchMsg( hab, &qmsg );
  554.     }
  555.  
  556.  
  557.     //--------------------------------------------------------------------------
  558.     // our application is done.  Destroy timer, window, the message queue and
  559.     // release the DLL.  Call the system to destroy anchor block and do the
  560.     // final clean up work
  561.     //--------------------------------------------------------------------------
  562.     if (timerNumber != 0)
  563.         WinStopTimer( hab, hwndFrame, timerNumber );
  564.     FileBarQuit();                                // release the DLL from memory
  565.     WinDestroyWindow(hwndFrame);
  566.     WinDestroyMsgQueue(hmq);
  567.     WinTerminate(hab);
  568.     return 0;
  569. }
  570.  
  571.  
  572. ////////////////////////////////////////////////////////////////////////////////
  573. // subclassed menu handler for main application window
  574. ////////////////////////////////////////////////////////////////////////////////
  575. MRESULT EXPENTRY menuHandler(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  576. {
  577.     switch (msg) {
  578.         //----------------------------------------------------------------------
  579.         // if a menu has been highlighted, save which one it is so that we know
  580.         // which task to affect if something is chosen off cascading menu
  581.         //----------------------------------------------------------------------
  582.         case WM_MENUSELECT:
  583.         {
  584.             if ((SHORT1FROMMP(mp1)>TASKLIST_MENU) && (SHORT1FROMMP(mp1)<99))
  585.                 taskItemSelected = SHORT1FROMMP(mp1);
  586.             return menuMessageHandler(hwnd, msg, mp1, mp2);
  587.         }
  588.         //----------------------------------------------------------------------
  589.         // resize menubar if a font was just dropped on us
  590.         //----------------------------------------------------------------------
  591.         case WM_PRESPARAMCHANGED:
  592.         {
  593.             if ( (ULONG)mp1 == PP_FONTNAMESIZE)
  594.                 resizeMenu();
  595.             return menuMessageHandler(hwnd, msg, mp1, mp2);
  596.         }
  597.         //----------------------------------------------------------------------
  598.         // nothing of interest, pass it onto the system for default processing
  599.         //----------------------------------------------------------------------
  600.         default:
  601.             break;
  602.         }
  603.     return menuMessageHandler(hwnd, msg, mp1, mp2);
  604. }
  605.  
  606.  
  607. //////////////////////////////////////////////////////////////////////////////
  608. // ask user for a password and check it against goodPassword and see if they
  609. // match.  Return boolean value that reflects this comparison
  610. //////////////////////////////////////////////////////////////////////////////
  611. BOOL checkAgainstPassWord( char* goodPassword )
  612. {
  613.     CHAR mesg[] = MSG3;
  614.  
  615.     sprintf( parameterTitle, MSG4 );
  616.     ParameterTextPtr = mesg;
  617.     oldProgType = PASSWORDLEN;
  618.     WinDlgBox(HWND_DESKTOP, hwndFrame, (PFNWP)EnterParamProc, 0,
  619.               PASSWORDENTRY, (PVOID)NULL);
  620.     if (strcmp( goodPassword, variableText ) == 0)
  621.         return TRUE;
  622.     WinMessageBox( HWND_DESKTOP, hwndFrame, MSG5,
  623.                    MSG6, 0, MB_MOVEABLE|MB_ERROR|MB_OK);
  624.     return FALSE;
  625. }
  626.  
  627.  
  628. //////////////////////////////////////////////////////////////////////////////
  629. // This is the message processing facility for the main application thread
  630. ////////////////////////////////////////////////////////////////////////////////
  631. MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  632. {
  633.     switch (msg) {
  634.         //----------------------------------------------------------------------
  635.         // if the application is terminating, write user settings to a file
  636.         //----------------------------------------------------------------------
  637.         case WM_CLOSE: {
  638.             if ((globalProtection==YES) && ( !checkAgainstPassWord(password) ))
  639.                 return FALSE;                // they entered an invalid password
  640.             writeOptionFile();
  641.             return WinDefWindowProc(hwnd, msg, mp1, mp2);  // default processing
  642.             }
  643.         case WM_SAVEAPPLICATION:
  644.         case WM_QUIT: {
  645.             writeOptionFile();
  646.             return WinDefWindowProc(hwnd, msg, mp1, mp2);  // default processing
  647.             }
  648.         //----------------------------------------------------------------------
  649.         // the application has been designed such that a WM_TIMER is sent by the
  650.         // system every minute (so that we can update our time on the menubar
  651.         // if necessary)
  652.         //----------------------------------------------------------------------
  653.         case WM_TIMER: {
  654.             if (!timeSync) {
  655.                 WinStopTimer( hab, hwndClient, timerNumber );
  656.                 timerNumber = WinStartTimer( hab, hwndClient, TIMERID, 60000);
  657.                 timeSync = TRUE;
  658.                 }
  659.             displayTimeDate();
  660.             return WinDefWindowProc(hwnd, msg, mp1, mp2);  // default processing
  661.             }
  662.         //----------------------------------------------------------------------
  663.         // a WM_INITMENU message is sent just prior to any pulldown menu being
  664.         // displayed.  This gives us a chance to change its contents before it
  665.         // is displayed.  If necessary, we update menu contents for user menus
  666.         //----------------------------------------------------------------------
  667.         case WM_INITMENU: {
  668.             SHORT menuId = SHORT1FROMMP(mp1);
  669.             //------------------------------------------------------------------
  670.             // if the FileBar menu is being readied for display, make sure the
  671.             // move-bar top/bottom item and check items read appropriately!
  672.             //------------------------------------------------------------------
  673.             if (menuId == FILEBAR_MENU) {
  674.                 HWND window = HWNDFROMMP( mp2 );
  675.  
  676.                 if (BarPosition == AT_TOP )
  677.                     WinSetMenuItemText( window, FILEBAR_MOVEBAR, MSG7 );
  678.                 else
  679.                     WinSetMenuItemText( window, FILEBAR_MOVEBAR, MSG8 );
  680.  
  681.                 WinCheckMenuItem( window, FILEBAR_STARTUP, DoStartUpList);
  682.                 WinCheckMenuItem( window, FILEBAR_DISPLAYBACKGROUND, showBackground);
  683.                 WinCheckMenuItem( window, FILEBAR_FILEBARMENU, (TRUE - FileBarMenuOn));
  684.                 WinCheckMenuItem( window, FILEBAR_CONFIRMCLOSE, checkBeforeDelete);
  685.                 WinCheckMenuItem( window, FILEBAR_RESIZEWPS, maximizeDesktop);
  686.                 WinCheckMenuItem( window, FILEBAR_INTERCEPTMSG, interceptMsg );
  687.                 WinCheckMenuItem( window, FILEBAR_JUMPTO, noJump );
  688.  
  689.                 if (!FileBarIsShell)
  690.                     WinEnableMenuItem( window, FILEBAR_RESIZEWPS, (BarPosition==AT_TOP));
  691.                 else {
  692.                     WinSendMsg( window, MM_DELETEITEM, MPFROM2SHORT( FILEBAR_EXIT, TRUE ), 0 );
  693.                     WinEnableMenuItem( window, FILEBAR_RESIZEWPS, FALSE);
  694.                     }
  695.                 return WinDefWindowProc(hwnd, msg, mp1, mp2);  // default processing
  696.                 }
  697.             //------------------------------------------------------------------
  698.             // if the user is pulling down the task list, put a current copy of
  699.             // the task list in the menu and store copies of all the tasks id
  700.             // numbers and handles just in case they want to jump to one of them
  701.             //------------------------------------------------------------------
  702.             if (menuId == TASKLIST_MENU) {
  703.                 SHORT i,j;
  704.                 PCHAR text;
  705.                 MENUITEM menuItem;
  706.                 USHORT index;
  707.                 ULONG numItems;
  708.                 ULONG Buffer;
  709.                 SWCNTRL tmp;
  710.                 PVOID my;
  711.  
  712.                 // clear out the menu, get it ready for new task entries
  713.                 for (i = menuId+1; i <= menuId+MAXITEMS; i++ )
  714.                     WinSendMsg( HWNDFROMMP( mp2 ), MM_DELETEITEM,
  715.                                 MPFROM2SHORT( i, TRUE ), 0 );
  716.  
  717.                 // get the # of items and the switch list from the system
  718.                 numItems = WinQuerySwitchList( hab, NULL, 0 );
  719.                 Buffer = (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
  720.                 my = new BYTE[Buffer];
  721.                 WinQuerySwitchList( hab, (SWBLOCK*)my, Buffer );
  722.  
  723.                 // insert each task as an entry under the task list menu
  724.                 menuItem.iPosition = 0;
  725.                 menuItem.afStyle = MIS_MULTMENU|MIS_SINGLE;
  726.                 menuItem.afAttribute = 0;
  727.                 menuItem.id = TASKLIST_MENU;
  728.  
  729.                 for (j = 0; j < numItems; j++ ) {
  730.                     tmp = ((PSWBLOCK)(my))->aswentry[j].swctl;
  731.                     menuItem.id++;
  732.                     if ((tmp.uchVisibility != SWL_GRAYED) &&
  733.                         (tmp.uchVisibility != SWL_INVISIBLE) &&
  734.                         (tmp.hwnd != hwndFrame)) {
  735.  
  736.                         // load in the cascading menu for this task entry
  737.                         menuItem.hwndSubMenu = WinLoadMenu(hwndMenu, 0, TASKMENUCLOSE);
  738.  
  739.                         // remove ctrl characters from task list
  740.                         index = 0;
  741.                         text = tmp.szSwtitle;
  742.                         while (text[++index])
  743.                             if (text[index]<' ')
  744.                                 text[index]=' ';
  745.  
  746.                         // enter task into the menu structure
  747.                         WinSendMsg( HWNDFROMMP(mp2), MM_INSERTITEM,
  748.                                     (MENUITEM*)&menuItem,
  749.                                     (tmp.szSwtitle) );
  750.  
  751.                         TaskId[j] = tmp.idProcess;
  752.                         TaskHandle[j] = tmp.hwnd;
  753.                         WinSetWindowBits(menuItem.hwndSubMenu, QWL_STYLE, MS_CONDITIONALCASCADE, MS_CONDITIONALCASCADE);
  754.                         WinSendMsg(menuItem.hwndSubMenu, MM_SETDEFAULTITEMID, MPFROMSHORT(TASK_SWITCHTO), NULL);
  755.                         }
  756.                     }
  757.                 delete( my );
  758.                 return WinDefWindowProc(hwnd, msg, mp1, mp2);  // default processing
  759.                 }
  760.             //------------------------------------------------------------------
  761.             // one of the user menus is being initialized; if it has been marked
  762.             // as needing to be updated, fill the menu with the current items
  763.             // the user has set up
  764.             //------------------------------------------------------------------
  765.             if (menuId >= 100) {
  766.                 int MenuToUpdate = menuId / 100 - 1;
  767.                 MENUITEM menuItem;
  768.                 SHORT i,j;
  769.  
  770.                 for (i = menuId+1; i < menuId+MAXITEMS+1; i++ )
  771.                     WinSendMsg( HWNDFROMMP( mp2 ), MM_DELETEITEM,
  772.                                 MPFROM2SHORT( i, TRUE ), 0 );
  773.                 menuItem.iPosition = MIT_END;
  774.                 menuItem.afStyle = MIS_TEXT;
  775.                 menuItem.afAttribute = 0;
  776.                 menuItem.hItem = 0;
  777.                 menuItem.hwndSubMenu = (HWND)0;
  778.                 menuItem.id = menuId;
  779.                 for (j = 0; j < NumItems[ MenuToUpdate ]; j++ ) {
  780.                     menuItem.id++;
  781.                     if (Menus[MenuToUpdate][j]->ItemName[0] != '\0')
  782.                         WinSendMsg( HWNDFROMMP(mp2), MM_INSERTITEM,
  783.                                     (MENUITEM*)&menuItem,
  784.                                     Menus[MenuToUpdate][j]->ItemName );
  785.                     else {
  786.                         menuItem.afStyle = MIS_SEPARATOR;
  787.                         WinSendMsg( HWNDFROMMP(mp2), MM_INSERTITEM,
  788.                                     (MENUITEM*)&menuItem,
  789.                                     0 );
  790.                         menuItem.afStyle = MIS_TEXT;
  791.                         }
  792.                     }
  793.                 }
  794.             }
  795.         //----------------------------------------------------------------------
  796.         // process all WM_COMMAND messages below:
  797.         //----------------------------------------------------------------------
  798.         case WM_COMMAND: {
  799.             USHORT command = SHORT1FROMMP(mp1);
  800.             //------------------------------------------------------------------
  801.             // it was not a user item, process now as usual
  802.             //------------------------------------------------------------------
  803.             switch( command ) {
  804.                 //--------------------------------------------------------------
  805.                 //--------------------------------------------------------------
  806.                 case FILEBAR_PASSWORD: {
  807.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  808.                         return 0;
  809.                     WinDlgBox(HWND_DESKTOP,
  810.                           hwnd,
  811.                           (PFNWP)globalPasswordProc,
  812.                           0,
  813.                           PASSWORDOPTIONS,
  814.                           (PVOID)NULL);
  815.                     return 0;
  816.                     }
  817.                 //--------------------------------------------------------------
  818.                 // user has invoked popup menu
  819.                 //--------------------------------------------------------------
  820.                 case POPUPMENU: {
  821.                     POINTL pointData;
  822.                     SHORT i;
  823.  
  824.                     // ignore if not clicked over desktop window
  825.                     if (((HWND)LONGFROMMP(mp2) != hwndDesktop) &&
  826.                         ((HWND)LONGFROMMP(mp2) != hwndWPS))
  827.                         return 0;
  828.  
  829.                     if (popUpMenu)
  830.                         WinDestroyWindow( popUpMenu );
  831.  
  832.                     popUpMenu = WinLoadMenu( HWND_DESKTOP, NULLHANDLE, MENUBAR );
  833.  
  834.                     for (i=0; i<MAXMENUS; i++)
  835.                         if (i<NumMenus)
  836.                             WinSetMenuItemText( popUpMenu, 100*i+100, MenuName[i] );
  837.                         else
  838.                             WinSendMsg( popUpMenu, MM_REMOVEITEM, MPFROM2SHORT(i*100+100,TRUE), 0 );
  839.                     updateTimeDisplay( popUpMenu );
  840.  
  841.                     WinQueryPointerPos( HWND_DESKTOP, &pointData );
  842.                     WinPopupMenu( HWND_DESKTOP, hwndMenu, popUpMenu, pointData.x, pointData.y, 0,
  843.                                   PU_HCONSTRAIN|PU_VCONSTRAIN|PU_MOUSEBUTTON1|PU_MOUSEBUTTON2|PU_MOUSEBUTTON3|PU_KEYBOARD );
  844.                     return 0;
  845.                     }
  846.                 //--------------------------------------------------------------
  847.                 // user wants to shutdown system
  848.                 //--------------------------------------------------------------
  849.                 case TASKLIST_SHUTDOWN: {
  850.                     char text[] = MSG9;
  851.  
  852.                     // Shutdown no longer requires a password to function
  853.                     //if (( globalProtection==YES ) &&
  854.                     //    ( !checkAgainstPassWord( password ) ))
  855.                     //    return FALSE;
  856.                     if (WinMessageBox( HWND_DESKTOP, hwndFrame, text, MSG10, 0,
  857.                                        MB_DEFBUTTON2|MB_MOVEABLE|MB_ICONEXCLAMATION|MB_OKCANCEL) == MBID_CANCEL)
  858.                         return 0;
  859.  
  860.                     writeOptionFile();
  861.                     WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_HIDE);
  862.                     WinPostMsg( hwndClient, WM_QUIT, 0, 0 );
  863.                     WinShutdownSystem( WinQueryAnchorBlock( HWND_DESKTOP ), hmq );
  864.                     }
  865.                 //--------------------------------------------------------------
  866.                 // expand or shrink FileBar system menus
  867.                 //--------------------------------------------------------------
  868.                 case FILEBAR_FILEBARMENU: {
  869.                     CHAR menuOn[] = FILEBARMENUON;
  870.                     CHAR menuOff[] = FILEBARMENUOFF;
  871.                     CHAR taskOn[] = TASKMENUON;
  872.                     CHAR taskOff[] = TASKMENUOFF;
  873.  
  874.                     FileBarMenuOn = TRUE - FileBarMenuOn;
  875.                     if (FileBarMenuOn) {
  876.                         WinSetMenuItemText( hwndMenu, FILEBAR_MENU, menuOn);
  877.                         WinSetMenuItemText( hwndMenu, TASKLIST_MENU, taskOn);
  878.                         }
  879.                     else {
  880.                         WinSetMenuItemText( hwndMenu, FILEBAR_MENU, menuOff);
  881.                         WinSetMenuItemText( hwndMenu, TASKLIST_MENU, taskOff);
  882.                         }
  883.                     return 0;
  884.                     }
  885.                 //--------------------------------------------------------------
  886.                 // the user has selected something from the tasklist menu, switch
  887.                 // control to that task, if possible
  888.                 //--------------------------------------------------------------
  889.                 case TASK_SWITCHTO: {
  890.                     CHAR title[] = MSG11;
  891.                     CHAR text[] = MSG12;
  892.                     HSWITCH switchHandle;
  893.                     switchHandle = WinQuerySwitchHandle( TaskHandle[taskItemSelected - TASKLIST_MENU-1],
  894.                                                          TaskId[taskItemSelected - TASKLIST_MENU-1]);
  895.  
  896.                     if (!switchHandle)
  897.                         WinMessageBox( HWND_DESKTOP, hwnd, text, title, 0,
  898.                                        MB_MOVEABLE|MB_ERROR|MB_OK);
  899.                     else if (WinSwitchToProgram( switchHandle ) != 0)
  900.                         WinMessageBox( HWND_DESKTOP, hwnd, text, title, 0,
  901.                                        MB_MOVEABLE|MB_ERROR|MB_OK);
  902.                     else
  903.                         WinShowWindow( TaskHandle[taskItemSelected - TASKLIST_MENU - 1], TRUE );
  904.                     return 0;
  905.                     }
  906.                 //--------------------------------------------------------------
  907.                 // close the chosen task
  908.                 //--------------------------------------------------------------
  909.                 case TASK_CLOSE: {
  910.                     ULONG numItems;
  911.                     ULONG Buffer;
  912.                     PSWBLOCK SwitchBlockPtr;
  913.                     PID killedTaskId;
  914.                     HWND killedTaskHandle;
  915.  
  916.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  917.                         return FALSE;
  918.  
  919.                     if (checkBeforeDelete) {
  920.                         if (WinMessageBox( HWND_DESKTOP, hwnd,
  921.                                            MSG13, MSG14, 0,
  922.                                            MB_MOVEABLE|MB_ICONQUESTION|MB_YESNO) == MBID_NO)
  923.                             return 0;
  924.                         }
  925.  
  926.                     killedTaskId = TaskId[taskItemSelected - TASKLIST_MENU - 1];
  927.                     killedTaskHandle = TaskHandle[taskItemSelected - TASKLIST_MENU - 1];
  928.                     WinSendMsg( killedTaskHandle, WM_CLOSE, 0, 0 );
  929.  
  930.                     // get the # of items and the switch list from the system
  931.                     numItems = WinQuerySwitchList( hab, NULL, 0 );
  932.                     Buffer = (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
  933.                     PVOID my = new BYTE[Buffer];
  934.                     WinQuerySwitchList( hab, (SWBLOCK*)my, Buffer );
  935.                     SwitchBlockPtr = (PSWBLOCK)(my);
  936.  
  937.                     // if task did not close willingly, kill its process!
  938.                     for (short j = 0; j < numItems; j++ )
  939.                         if (SwitchBlockPtr->aswentry[j].swctl.hwnd == killedTaskHandle)
  940.                             DosKillProcess( DKP_PROCESS, killedTaskId );
  941.                     delete( my );
  942.  
  943.                     return 0;
  944.                     }
  945.                 //-------------------------------------------------------------
  946.                 // maximize the chosen task
  947.                 //-------------------------------------------------------------
  948.                 case TASK_MAX: {
  949.                     HSWITCH switchHandle = WinQuerySwitchHandle( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
  950.                                                                  TaskId[taskItemSelected - TASKLIST_MENU- 1]);
  951.  
  952.                     WinShowWindow( TaskHandle[taskItemSelected - TASKLIST_MENU- 1], TRUE );
  953.                     WinSetWindowPos( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
  954.                                      (HWND)0, 0, 0, 0, 0, SWP_MAXIMIZE);
  955.                     WinSwitchToProgram( switchHandle );
  956.                     return 0;
  957.                     }
  958.                 //--------------------------------------------------------------
  959.                 // minimize the chosen task
  960.                 //--------------------------------------------------------------
  961.                 case TASK_MIN: {
  962.                     WinShowWindow( TaskHandle[taskItemSelected - TASKLIST_MENU- 1], TRUE );
  963.                     WinSetWindowPos( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
  964.                                      (HWND)0, 0, 0, 0, 0, SWP_MINIMIZE);
  965.                     return 0;
  966.                     }
  967.                 //--------------------------------------------------------------
  968.                 // show the chosen task
  969.                 //--------------------------------------------------------------
  970.                 case TASK_SHOW: {
  971.                     WinSetWindowPos( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
  972.                                      (HWND)0, 0, 0, 0, 0, SWP_SHOW);
  973.                     return 0;
  974.                     }
  975.                 //--------------------------------------------------------------
  976.                 // hide the chosen task
  977.                 //--------------------------------------------------------------
  978.                 case TASK_HIDE: {
  979.                     WinSetWindowPos( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
  980.                                      (HWND)0, 0, 0, 0, 0, SWP_HIDE);
  981.                     return 0;
  982.                     }
  983.                 //--------------------------------------------------------------
  984.                 // show the display background dialog box
  985.                 //--------------------------------------------------------------
  986.                 case FILEBAR_DISPLAYBACKGROUND: {
  987.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  988.                         return FALSE;
  989.                     WinDlgBox(HWND_DESKTOP,
  990.                           hwnd,
  991.                           (PFNWP)backgroundProc,
  992.                           0,
  993.                           BACKGROUNDWIN,
  994.                           (PVOID)NULL);
  995.                     displayBackground();
  996.                     return 0;
  997.                     }
  998.                 //--------------------------------------------------------------
  999.                 // user has altered "confirm on task close" check state
  1000.                 //--------------------------------------------------------------
  1001.                 case FILEBAR_CONFIRMCLOSE: {
  1002.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  1003.                         return FALSE;
  1004.                     checkBeforeDelete = TRUE - checkBeforeDelete;
  1005.                     return 0;
  1006.                     }
  1007.                 //--------------------------------------------------------------
  1008.                 //--------------------------------------------------------------
  1009.                 case FILEBAR_JUMPTO: {
  1010.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  1011.                         return FALSE;
  1012.                     noJump = TRUE - noJump;
  1013.                     return 0;
  1014.                     }
  1015.                 //--------------------------------------------------------------
  1016.                 // user has altered check state of "always on top" item
  1017.                 //--------------------------------------------------------------
  1018.                 case FILEBAR_INTERCEPTMSG: {
  1019.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  1020.                         return FALSE;
  1021.                     interceptMsg = TRUE - interceptMsg;
  1022.                     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  1023.                                       allowPopUpMenu, popUpMessageID );
  1024.                     return 0;
  1025.                     }
  1026.                 //--------------------------------------------------------------
  1027.                 // show the display background dialog box
  1028.                 //--------------------------------------------------------------
  1029.                 case FILEBAR_STARTUP: {
  1030.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  1031.                         return FALSE;
  1032.                     WinDlgBox(HWND_DESKTOP,
  1033.                               hwnd,
  1034.                               (PFNWP)startupProc,
  1035.                               0,
  1036.                               STARTUP_DIALOG,
  1037.                              (PVOID)NULL);
  1038.                     return 0;
  1039.                     }
  1040.                 //--------------------------------------------------------------
  1041.                 // user has invoked the scheduler
  1042.                 //--------------------------------------------------------------
  1043.                 case TIMEDATE: {
  1044.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  1045.                         return FALSE;
  1046.                     WinDlgBox(HWND_DESKTOP,
  1047.                               hwnd,
  1048.                               (PFNWP)schedulerProc,
  1049.                               0,
  1050.                               SCHEDULER,
  1051.                               (PVOID)NULL);
  1052.                     return 0;
  1053.                 }
  1054.                 //--------------------------------------------------------------
  1055.                 // uer has altered check state of "resize desktop on boot" item
  1056.                 //--------------------------------------------------------------
  1057.                 case FILEBAR_RESIZEWPS: {
  1058.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  1059.                         return FALSE;
  1060.                     maximizeDesktop = TRUE - maximizeDesktop;
  1061.                     return 0;
  1062.                     }
  1063.                 //--------------------------------------------------------------
  1064.                 // user wants to change settings of popup menu
  1065.                 //--------------------------------------------------------------
  1066.                 case FILEBAR_POPMENU: {
  1067.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  1068.                         return FALSE;
  1069.                     WinDlgBox(HWND_DESKTOP,
  1070.                               hwnd,
  1071.                               (PFNWP)popUpOptionsProc,
  1072.                               0,
  1073.                               POPUPOPTIONS,
  1074.                               (PVOID)NULL);
  1075.                     return 0;
  1076.                     }
  1077.                 //--------------------------------------------------------------
  1078.                 // the user wants to save current options
  1079.                 //--------------------------------------------------------------
  1080.                 case FILEBAR_SAVEOPTIONS: {
  1081.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  1082.                         return FALSE;
  1083.                     writeOptionFile();
  1084.                     WinMessageBox( HWND_DESKTOP, hwnd, MSG16, MSG15, 0,
  1085.                                    MB_MOVEABLE|MB_INFORMATION|MB_OK);
  1086.                     return 0;
  1087.                 }
  1088.                 //--------------------------------------------------------------
  1089.                 // the user wants to edit the menu structure
  1090.                 //--------------------------------------------------------------
  1091.                 case FILEBAR_EDITMENU: {
  1092.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  1093.                         return FALSE;
  1094.                     return (VOID*)WinDlgBox(HWND_DESKTOP,
  1095.                                             hwnd,
  1096.                                             (PFNWP)EditMenuProc,
  1097.                                             0,
  1098.                                             EDITMENU,
  1099.                                             (PVOID)NULL);
  1100.                     }
  1101.                 //--------------------------------------------------------------
  1102.                 // the user wants to select their time/date display options
  1103.                 //--------------------------------------------------------------
  1104.                 case FILEBAR_TIMEOPTION: {
  1105.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  1106.                         return FALSE;
  1107.                     return (VOID*)WinDlgBox(HWND_DESKTOP,
  1108.                                             hwnd,
  1109.                                             (PFNWP)TimeDateProc,
  1110.                                             0,
  1111.                                             TIMEOPTIONS,
  1112.                                             (PVOID)NULL);
  1113.                     }
  1114.                 //--------------------------------------------------------------
  1115.                 // the user wants to get general help on filebar
  1116.                 //--------------------------------------------------------------
  1117.                 case FILEBAR_GENHELP: {
  1118.                     return (VOID*)WinDlgBox(HWND_DESKTOP,
  1119.                                             hwnd,
  1120.                                             (PFNWP)GenericProc,
  1121.                                             0,
  1122.                                             GENERAL_HELP,
  1123.                                             (PVOID)NULL);
  1124.                     }
  1125.                 //--------------------------------------------------------------
  1126.                 // the user wants to see product information for filebar
  1127.                 //--------------------------------------------------------------
  1128.                 case FILEBAR_PRODINFO: {
  1129.                     #ifndef SDS_VERSION
  1130.                     (VOID*)WinDlgBox(HWND_DESKTOP,
  1131.                                      hwnd,
  1132.                                      (PFNWP)GenericProc,
  1133.                                      0,
  1134.                                      PRODUCT_INFO,
  1135.                                      (PVOID)NULL);
  1136.             #else
  1137.                     (VOID*)WinDlgBox(HWND_DESKTOP,
  1138.                                      hwnd,
  1139.                                      (PFNWP)GenericProc,
  1140.                                      0,
  1141.                                      PRODUCT_INFO2,
  1142.                                      (PVOID)NULL);
  1143.                     #endif
  1144.  
  1145.                     #ifndef SDS_VERSION
  1146.                     (VOID*)WinDlgBox(HWND_DESKTOP,
  1147.                                             hwnd,
  1148.                                             (PFNWP)GenericProc,
  1149.                                             0,
  1150.                                             INFORMATION,
  1151.                                             (PVOID)NULL);
  1152.                     #endif
  1153.                     return 0;
  1154.                     }
  1155.                 //--------------------------------------------------------------
  1156.                 // the user wishes to move the filebar from its current position
  1157.                 // to either to the top or bottom of the desktop
  1158.                 //--------------------------------------------------------------
  1159.                 case FILEBAR_MOVEBAR: {
  1160.                     if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  1161.                         return FALSE;
  1162.                     if (BarPosition==AT_TOP) {
  1163.                         BarPosition = AT_BOTTOM;
  1164.                         WinSetWindowPos( hwndFrame, (HWND)0, 0, -1,
  1165.                                          ScreenSizeX, MenuHeight, SWP_MOVE);
  1166.                         }
  1167.                     else {
  1168.                         BarPosition = AT_TOP;
  1169.                         WinSetWindowPos( hwndFrame, (HWND)0, 0, (ScreenSizeY-MenuHeight)+1,
  1170.                                          ScreenSizeX, MenuHeight, SWP_MOVE);
  1171.                         }
  1172.                     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  1173.                                       allowPopUpMenu, popUpMessageID );
  1174.                     return 0;
  1175.                     }
  1176.                 //--------------------------------------------------------------
  1177.                 // the user wishes to exit the filebar application
  1178.                 //--------------------------------------------------------------
  1179.                 case FILEBAR_EXIT: {
  1180.                     return (VOID*)WinPostMsg( hwnd, WM_CLOSE, 0, 0);
  1181.                     }
  1182.                 //--------------------------------------------------------------
  1183.                 // something besides our menus sent a message, pass the message
  1184.                 // to the system for default processing
  1185.                 //--------------------------------------------------------------
  1186.                 default:
  1187.                     break;
  1188.                 }
  1189.  
  1190.             //------------------------------------------------------------------
  1191.             // the user has selected an item off the user menus.  Activate the
  1192.             // item they have selected
  1193.             //------------------------------------------------------------------
  1194.             if (( command > 99 ) && (command % 100)) {
  1195.                 INT MenuToUpdate = command / 100 - 1;
  1196.                 INT ItemToUpdate = command % 100 - 1;
  1197.  
  1198.                 if ((ItemToUpdate>=MAXITEMS) || (MenuToUpdate>=MAXMENUS))
  1199.                     return 0;
  1200.                 if (MenuToUpdate >= 0)
  1201.                     if ( Menus[MenuToUpdate][ItemToUpdate]->PasswordEnabled == YES )
  1202.                         if ( !checkAgainstPassWord( Menus[MenuToUpdate][ItemToUpdate]->Password ) )
  1203.                             return FALSE;
  1204.                     startApplication( MenuToUpdate, ItemToUpdate );
  1205.                 return 0;
  1206.                 }
  1207.  
  1208.             }
  1209.         //----------------------------------------------------------------------
  1210.         // we were sent a message that we don't care about, pass it onto system
  1211.         // for default processing
  1212.         //----------------------------------------------------------------------
  1213.         default:
  1214.             break;
  1215.         };
  1216.  
  1217.     return WinDefWindowProc(hwnd, msg, mp1, mp2);  // default processing
  1218. }
  1219.  
  1220.  
  1221. ////////////////////////////////////////////////////////////////////////////////
  1222. // readOptionFile - will read the option file (generated by the app) from disk,
  1223. // if it exists and will restore the application to the state in which it was
  1224. // last left
  1225. ////////////////////////////////////////////////////////////////////////////////
  1226. void readOptionFile( void )
  1227. {
  1228.     int currentMenu = 100;
  1229.     FILE *optionFile;
  1230.  
  1231.     //--------------------------------------------------------------------------
  1232.     // if the option file exists on disk, read it in and restore old menu,
  1233.     // otherwise we will return and rely on default values
  1234.     //--------------------------------------------------------------------------
  1235.     //if (settingsPath)
  1236.     //    optionFile = fopen(settingsPath, "rt");
  1237.     //else
  1238.     optionFile = fopen(OPTIONFILE, "rt");
  1239.  
  1240.     if (optionFile != NULL) {
  1241.         ALARMS* alarm;
  1242.         USERMENUITEM* menuItem;
  1243.         RGB2 rgb = {0,0,0,0};
  1244.         ULONG color;
  1245.         INT a,b,c,d,e,f;
  1246.  
  1247.         MenuHeight  = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2;
  1248.  
  1249.         fscanf(optionFile, "%d %d", &timeOption, &BarPosition);
  1250.         // restore user's desired bar position
  1251.         if (BarPosition==AT_BOTTOM) {
  1252.             WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0 , SWP_MOVE|SWP_RESTORE);
  1253.             WinSetWindowPos( hwndFrame, (HWND)0, 0, -1,
  1254.                              ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE);
  1255.             WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0 , SWP_MOVE|SWP_MINIMIZE);
  1256.             }
  1257.         else {
  1258.             WinSetWindowPos( hwndFrame, (HWND)0, 0, (ScreenSizeY-MenuHeight)+1,
  1259.                              ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE);
  1260.             }
  1261.         setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  1262.                           allowPopUpMenu, popUpMessageID );
  1263.  
  1264.         // restore user's menus and menu choices
  1265.         fscanf(optionFile, "%d", &NumMenus);
  1266.         for (short i = 0; i < NumMenus; i++ ) {
  1267.             readString( optionFile, (CHAR*)&MenuName[i] );
  1268.  
  1269.             WinSendMsg( hwndMenu, MM_SETITEM, MPFROM2SHORT(100*i+100,TRUE),MPFROMP(&menuData[i]));
  1270.             /////////////////////WinSetMenuItemText( hwndMenu, 100*i+100, &MenuName[i]);
  1271.             WinSetMenuItemText( hwndMenu, 100*i+100, MenuName[i]);
  1272.  
  1273.             fscanf(optionFile, "%d", &a);
  1274.             NumItems[i] = (BYTE)(a % 256);
  1275.             for (short j = 0; j < NumItems[i]; j++) {
  1276.                 Menus[i][j] = new USERMENUITEM;
  1277.                 menuItem = Menus[i][j];
  1278.                 readString( optionFile, (CHAR*)&menuItem->ItemName );
  1279.                 readString( optionFile, (CHAR*)&menuItem->ActionToDo );
  1280.                 readString( optionFile, (CHAR*)&menuItem->CmdLnArgs );
  1281.                 readString( optionFile, (CHAR*)&menuItem->Directory );
  1282.                 fscanf( optionFile, "%d", &a );
  1283.                 menuItem->ProgType = a % 1024;
  1284.                 menuItem->PasswordEnabled = NO;
  1285.                 menuItem->Password[0] = 0;
  1286.                 }
  1287.             currentMenu = currentMenu + 100;
  1288.             }
  1289.  
  1290.         readString( optionFile, (CHAR*)&tmpBuffer );
  1291.         if (tmpBuffer[0]!='\0') {
  1292.             WinSetPresParam( hwndMenu, PP_FONTNAMESIZE, sizeof(tmpBuffer), tmpBuffer );
  1293.             WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_RESTORE);
  1294.             resizeMenu();
  1295.             WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_MINIMIZE);
  1296.             }
  1297.  
  1298.         fscanf( optionFile, "%d", &checkBeforeDelete );
  1299.         if (fscanf( optionFile, "%d", &FileBarMenuOn )!=EOF) {
  1300.             CHAR menuOn[] = FILEBARMENUON;
  1301.             CHAR menuOff[] = FILEBARMENUOFF;
  1302.             CHAR taskOn[] = TASKMENUON;
  1303.             CHAR taskOff[] = TASKMENUOFF;
  1304.  
  1305.             if (FileBarMenuOn) {
  1306.                 WinSetMenuItemText( hwndMenu, FILEBAR_MENU, menuOn);
  1307.                 WinSetMenuItemText( hwndMenu, TASKLIST_MENU, taskOn);
  1308.                 }
  1309.             else {
  1310.                 WinSetMenuItemText( hwndMenu, FILEBAR_MENU, menuOff);
  1311.                 WinSetMenuItemText( hwndMenu, TASKLIST_MENU, taskOff);
  1312.                 }
  1313.             }
  1314.  
  1315.         if (fscanf( optionFile, "%d %d", &showBackground, &backgroundAttr )!=EOF)
  1316.             readString( optionFile, (CHAR*)&backgroundBitmap );
  1317.  
  1318.         for (i=PP_FOREGROUNDCOLOR; i<=PP_BORDERCOLOR; i=i+2)
  1319.             if (fscanf(optionFile, "%ld", &color )!=EOF)
  1320.                 if ( color != NOCOLOR) {
  1321.                     rgb.bRed = (BYTE)(color/65536);
  1322.                     color = color%65536;
  1323.                     rgb.bGreen = (BYTE)(color/256);
  1324.                     color = color%256;
  1325.                     rgb.bBlue = (BYTE)(color);
  1326.                     WinSetPresParam( hwndMenu, i, sizeof(rgb), &rgb);
  1327.                     }
  1328.  
  1329.         for (i=PP_ACTIVECOLOR; i<=PP_INACTIVETEXTBGNDCOLOR; i=i+2)
  1330.             if (fscanf(optionFile, "%ld", &color )!=EOF)
  1331.                 if ( color != NOCOLOR) {
  1332.                     rgb.bRed = (BYTE)(color/65536);
  1333.                     color = color%65536;
  1334.                     rgb.bGreen = (BYTE)(color/256);
  1335.                     color = color%256;
  1336.                     rgb.bBlue = (BYTE)(color);
  1337.                     WinSetPresParam( hwndMenu, i, sizeof(rgb), &rgb);
  1338.                     }
  1339.  
  1340.         if (fscanf(optionFile, "%ld", &color )!=EOF)
  1341.             if ( color != NOCOLOR) {
  1342.                 rgb.bRed = (BYTE)(color/65536);
  1343.                 color = color%65536;
  1344.                 rgb.bGreen = (BYTE)(color/256);
  1345.                 color = color%256;
  1346.                 rgb.bBlue = (BYTE)(color);
  1347.                 WinSetPresParam( hwndMenu, PP_SHADOW, sizeof(rgb), &rgb);
  1348.                 }
  1349.  
  1350.         for (i=PP_MENUFOREGROUNDCOLOR; i<=PP_MENUDISABLEDBGNDCOLOR; i=i+2)
  1351.             if (fscanf(optionFile, "%ld", &color )!=EOF)
  1352.                 if ( color != NOCOLOR) {
  1353.                     rgb.bRed = (BYTE)(color/65536);
  1354.                     color = color%65536;
  1355.                     rgb.bGreen = (BYTE)(color/256);
  1356.                     color = color%256;
  1357.                     rgb.bBlue = (BYTE)(color);
  1358.                     WinSetPresParam( hwndMenu, i, sizeof(rgb), &rgb);
  1359.                     }
  1360.  
  1361.         if (fscanf(optionFile, "%d %d", &DoStartUpList, &numStartItems ) != EOF)
  1362.             for (i=0; i<numStartItems; i++)
  1363.                 fscanf(optionFile, "%d %d", &StartUpMenu[i], &StartUpItem[i] );
  1364.  
  1365.         if (fscanf(optionFile, "%d", &HourlyChime ) != EOF)
  1366.             readString( optionFile, (CHAR*)&hourlyChimeWavFile );
  1367.  
  1368.         // read in current task scheduler tasks
  1369.         if (fscanf(optionFile, "%d %d %d %d", &maximizeDesktop, &repeatTime, &interceptMsg, &numAlarms ) != EOF) {
  1370.             setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  1371.                               allowPopUpMenu, popUpMessageID );
  1372.  
  1373.             for (i=0; i<numAlarms; i++) {
  1374.                 fscanf(optionFile, "%d %d %d %d %d %d", &a,&b,&c,&d,&e,&f);
  1375.                 alarmPtr[i] = new ALARMS;
  1376.                 alarm = alarmPtr[i];
  1377.                 alarm->AlarmHour   = a % 256;
  1378.                 alarm->AlarmMinute = b % 256;
  1379.                 alarm->AlarmMonth  = c % 256;
  1380.                 alarm->AlarmDay    = d % 256;
  1381.                 alarm->AlarmYear   = e % 256;
  1382.                 alarm->options     = f % 256;
  1383.                 readString( optionFile, (CHAR*)&alarm->ActionToDo );
  1384.                 readString( optionFile, (CHAR*)&alarm->ReminderWAV );
  1385.                 }
  1386.         }
  1387.  
  1388.         fscanf(optionFile, "%d %d", &hideFileBar, &allowPopUpMenu );
  1389.         fscanf(optionFile, "%ld", &popUpMessageID );
  1390.  
  1391.         setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  1392.                            allowPopUpMenu, popUpMessageID );
  1393.  
  1394.         // read password for FileBar system administrator and tasks
  1395.         readString( optionFile, (CHAR*)&password );
  1396.         if (!password[0])
  1397.             strcpy( password, DEFAULTPASSWORD );
  1398.  
  1399.         for (i = 0; i < NumMenus; i++ )
  1400.             for (short j = 0; j < NumItems[i]; j++) {
  1401.                 readString( optionFile, (CHAR*)&Menus[i][j]->Password );
  1402.                 if (!Menus[i][j]->Password[0])
  1403.                     strcpy( Menus[i][j]->Password, DEFAULTPASSWORD );
  1404.                 }
  1405.  
  1406.         fscanf( optionFile, "%d", &a );
  1407.         globalProtection = a % 256;
  1408.  
  1409.         readString( optionFile, (CHAR*)&tmpBuffer );
  1410.         for (i = 0; i < NumMenus; i++ )
  1411.             for (short j = 0; j < NumItems[i]; j++)
  1412.                 fscanf( optionFile, "%c", &(Menus[i][j]->PasswordEnabled) );
  1413.         readString( optionFile, (CHAR*)&tmpBuffer );
  1414.         fscanf( optionFile, "%d", &noJump );
  1415.  
  1416.         fclose( optionFile );
  1417.         }
  1418. }
  1419.  
  1420.  
  1421. ////////////////////////////////////////////////////////////////////////////////
  1422. // writeOptionFile - will write the application state to the option file
  1423. ////////////////////////////////////////////////////////////////////////////////
  1424. void writeOptionFile( void )
  1425. {
  1426.     SHORT currentMenu = 100;
  1427.     FILE *optionFile;
  1428.  
  1429.     //--------------------------------------------------------------------------
  1430.     // if the option file exists on disk, read it in and restore old menu,
  1431.     // otherwise we will return and rely on default values
  1432.     //--------------------------------------------------------------------------
  1433.     //if (settingsPath)
  1434.     //    optionFile = fopen(settingsPath, "wt");
  1435.     //else
  1436.     optionFile = fopen(OPTIONFILE, "wt");
  1437.  
  1438.     if (optionFile == NULL)
  1439.         // if not able to save, alert the user
  1440.         WinMessageBox( HWND_DESKTOP, hwndClient, MSG17,
  1441.                        0, 0, MB_MOVEABLE|MB_ERROR|MB_OK);
  1442.     else {
  1443.         ULONG length;
  1444.         RGB2 rgb;
  1445.         ALARMS* alarm;
  1446.         USERMENUITEM* menuItem;
  1447.  
  1448.         // save user's desired bar position
  1449.         //fprintf(optionFile, "%d %d\n", timeOption, BarPosition);
  1450.         // save user's menus and menu choices
  1451.         //fprintf(optionFile, "%d\n", NumMenus);
  1452.         fprintf(optionFile, "%d %d %d\n", timeOption, BarPosition, NumMenus);
  1453.         for (short i = 0; i < NumMenus; i++ ) {
  1454.             writeString( optionFile, (CHAR*)MenuName[i] );
  1455.             fprintf(optionFile, "%d\n", NumItems[i]);
  1456.             for (short j = 0; j < NumItems[i]; j++) {
  1457.                 menuItem = Menus[i][j];
  1458.                 writeString( optionFile, (CHAR*)menuItem->ItemName );
  1459.                 writeString( optionFile, (CHAR*)menuItem->ActionToDo );
  1460.                 writeString( optionFile, (CHAR*)menuItem->CmdLnArgs );
  1461.                 writeString( optionFile, (CHAR*)menuItem->Directory );
  1462.                 fprintf( optionFile, "%d\n", menuItem->ProgType );
  1463.                 }
  1464.             currentMenu = currentMenu + 100;
  1465.             }
  1466.  
  1467.         if (WinQueryPresParam( hwndMenu, PP_FONTNAMESIZE, 0, &length, sizeof(tmpBuffer), tmpBuffer, 0)!=FALSE)
  1468.             writeString( optionFile, (CHAR*)tmpBuffer );
  1469.         else
  1470.             writeString( optionFile, "" );
  1471.             //fprintf( optionFile, "\"\"\n" );
  1472.         fprintf( optionFile, "%d %d %d %d\n", checkBeforeDelete, FileBarMenuOn, showBackground, backgroundAttr );
  1473.         writeString( optionFile, (CHAR*)backgroundBitmap );
  1474.  
  1475.         // save menu scheme of colors
  1476.         for (i=PP_FOREGROUNDCOLOR; i<=PP_BORDERCOLOR; i=i+2)
  1477.             if (WinQueryPresParam( hwndMenu, i, 0, 0, sizeof(rgb), &rgb, 0))
  1478.                 fprintf(optionFile, "%ld\n", (ULONG)(rgb.bRed*65536+rgb.bGreen*256+rgb.bBlue) );
  1479.             else fprintf(optionFile, "%ld\n", NOCOLOR );
  1480.  
  1481.         for (i=PP_ACTIVECOLOR; i<=PP_INACTIVETEXTBGNDCOLOR; i=i+2)
  1482.             if (WinQueryPresParam( hwndMenu, i, 0, 0, sizeof(rgb), &rgb, 0))
  1483.                 fprintf(optionFile, "%ld\n", (ULONG)(rgb.bRed*65536+rgb.bGreen*256+rgb.bBlue) );
  1484.             else fprintf(optionFile, "%ld\n", NOCOLOR );
  1485.  
  1486.         if (WinQueryPresParam( hwndMenu, PP_SHADOW, 0, 0, sizeof(rgb), &rgb, 0))
  1487.             fprintf(optionFile, "%ld\n", (ULONG)(rgb.bRed*65536+rgb.bGreen*256+rgb.bBlue) );
  1488.         else fprintf(optionFile, "%ld\n", NOCOLOR );
  1489.  
  1490.         for (i=PP_MENUFOREGROUNDCOLOR; i<=PP_MENUDISABLEDBGNDCOLOR; i=i+2)
  1491.             if (WinQueryPresParam( hwndMenu, i, 0, 0, sizeof(rgb), &rgb, 0))
  1492.                 fprintf(optionFile, "%ld\n", (ULONG)(rgb.bRed*65536+rgb.bGreen*256+rgb.bBlue) );
  1493.             else fprintf(optionFile, "%ld\n", NOCOLOR );
  1494.  
  1495.         fprintf(optionFile, "%d\n%d\n", DoStartUpList, numStartItems );
  1496.         for (i=0; i<numStartItems; i++)
  1497.             fprintf(optionFile, "%d\n%d\n", StartUpMenu[i], StartUpItem[i] );
  1498.  
  1499.         fprintf(optionFile, "%d\n", HourlyChime );
  1500.         writeString( optionFile, (CHAR*)hourlyChimeWavFile );
  1501.  
  1502.         // save current task scheduler items
  1503.         fprintf(optionFile, "%d %d %d %d\n", maximizeDesktop, repeatTime, interceptMsg, numAlarms );
  1504.         for (i=0; i<numAlarms; i++) {
  1505.             alarm = alarmPtr[i];
  1506.             fprintf(optionFile, "%d %d %d %d %d %d\n", alarm->AlarmHour,
  1507.                                                        alarm->AlarmMinute,
  1508.                                                        alarm->AlarmMonth,
  1509.                                                        alarm->AlarmDay,
  1510.                                                        alarm->AlarmYear,
  1511.                                                        alarm->options );
  1512.             writeString( optionFile, (CHAR*)alarm->ActionToDo );
  1513.             writeString( optionFile, (CHAR*)alarm->ReminderWAV );
  1514.             }
  1515.         fprintf( optionFile, "%d %d\n", hideFileBar, allowPopUpMenu );
  1516.         fprintf( optionFile, "%ld\n", popUpMessageID );
  1517.  
  1518.         writeString( optionFile, (CHAR*)password );
  1519.         for (i = 0; i < NumMenus; i++ )
  1520.             for (short j = 0; j < NumItems[i]; j++)
  1521.                 writeString( optionFile, (CHAR*)Menus[i][j]->Password );
  1522.         fprintf( optionFile, "%d\n", globalProtection );
  1523.  
  1524.         writeString( optionFile, "" );
  1525.         for (i = 0; i < NumMenus; i++ )
  1526.             for (short j = 0; j < NumItems[i]; j++)
  1527.                 fprintf( optionFile, "%c", Menus[i][j]->PasswordEnabled );
  1528.         writeString( optionFile, "" );
  1529.         fprintf( optionFile, "%d\n", noJump );
  1530.  
  1531.         fclose( optionFile );
  1532.         }
  1533. }
  1534.  
  1535.  
  1536. ////////////////////////////////////////////////////////////////////////////////
  1537. // readString will read a sequence of characters that is bounded on both sides
  1538. // by quote (") characters (We can't use fscanf because it won't read spaces)
  1539. ////////////////////////////////////////////////////////////////////////////////
  1540. VOID readString( FILE* stream, CHAR* buffer )
  1541. {
  1542.     if (stringTerminator)
  1543.         do                                       // search for first " character
  1544.           if (fscanf( stream, "%c", buffer)==EOF) break;
  1545.           while ( (*buffer) != stringTerminator);
  1546.     else {
  1547.         do                                       // search for first " character
  1548.           if (fscanf( stream, "%c", buffer)==EOF) break;
  1549.           while ( ((*buffer) !='\"') && ((*buffer) != TERMCHAR) );
  1550.         stringTerminator= (*buffer);
  1551.         }
  1552.     buffer--;
  1553.     do {                               // keep putting characters into the buffer
  1554.         buffer++;                      // " character
  1555.         if (fscanf( stream, "%c", buffer)==EOF) break;
  1556.     } while ( (*buffer) != stringTerminator);
  1557.     *buffer = '\0';                    // store a NULL to terminate the string
  1558. }
  1559.  
  1560.  
  1561. ////////////////////////////////////////////////////////////////////////////////
  1562. // a new font has been selected for our menu, resize and redraw the menubar
  1563. ////////////////////////////////////////////////////////////////////////////////
  1564. VOID resizeMenu()
  1565. {
  1566.     HPS hps;
  1567.     FONTMETRICS fm;
  1568.  
  1569.     hps = WinGetPS( hwndMenu );
  1570.     GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fm);
  1571.     MenuHeight = fm.lLowerCaseDescent + fm.lMaxAscender + 4;
  1572.     if (MenuHeight < (fm.lLowerCaseDescent + fm.lLowerCaseAscent + 2))
  1573.         MenuHeight = fm.lLowerCaseDescent + fm.lLowerCaseAscent + 2;
  1574.     if (MenuHeight < (WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2))
  1575.         MenuHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2;
  1576.     WinReleasePS( hps );
  1577.  
  1578.     if (BarPosition==AT_BOTTOM)
  1579.         WinSetWindowPos( hwndFrame, (HWND)0, 0, -1,
  1580.                          ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE);
  1581.     else
  1582.         WinSetWindowPos( hwndFrame, (HWND)0, 0, (ScreenSizeY-MenuHeight)+1,
  1583.                          ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE);
  1584.     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight,
  1585.                       (interceptMsg==TRUE), allowPopUpMenu, popUpMessageID );
  1586. }
  1587.  
  1588.  
  1589. ////////////////////////////////////////////////////////////////////////////////
  1590. // Message handler for a generic information-only dialog box (help & prod info)
  1591. ////////////////////////////////////////////////////////////////////////////////
  1592. MRESULT EXPENTRY GenericProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  1593. {
  1594.    switch( msg )
  1595.     {
  1596.         //----------------------------------------------------------------------
  1597.         // when the dialog is being initialized, center it on desktop
  1598.         //----------------------------------------------------------------------
  1599.         case WM_INITDLG: {
  1600.             SWP swp;
  1601.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  1602.             WinSetWindowPos( hWnd, (HWND)0,
  1603.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  1604.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  1605.                              0, 0, SWP_MOVE);
  1606.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  1607.             }
  1608.         //----------------------------------------------------------------------
  1609.         // if we receive any system message, dismiss the dialog box
  1610.         //----------------------------------------------------------------------
  1611.         case WM_COMMAND:
  1612.         {
  1613.             WinDismissDlg( hWnd, TRUE );
  1614.             return 0;
  1615.         }
  1616.         //----------------------------------------------------------------------
  1617.         // if nothing further we want to intercept, pass message onto system
  1618.         //----------------------------------------------------------------------
  1619.         default:
  1620.             break;
  1621.     }
  1622.     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  1623. }
  1624.  
  1625.  
  1626. ////////////////////////////////////////////////////////////////////////////////
  1627. // starts or restarts a timer to signal our program when the next minute occurs
  1628. ////////////////////////////////////////////////////////////////////////////////
  1629. VOID restartTimer( VOID )
  1630. {
  1631.     struct tm *time_now;
  1632.     time_t currentTime;
  1633.  
  1634.     tzset();
  1635.     time(¤tTime);
  1636.     time_now = localtime( ¤tTime );
  1637.     timeSync = FALSE;
  1638.  
  1639.     timerNumber = WinStartTimer( hab, hwndClient, TIMERID, (60-(time_now->tm_sec))*1000);
  1640. }
  1641.  
  1642.  
  1643. ////////////////////////////////////////////////////////////////////////////////
  1644. // ringChime - play a .WAV file sent to us as the parameter.
  1645. ////////////////////////////////////////////////////////////////////////////////
  1646. VOID ringChime( CHAR* soundFile )
  1647. {
  1648.     APIRET rc;
  1649.     char mesg[MAXPATH+384];
  1650.     RXSTRING  INSTORE[2];
  1651.     RXSTRING  retstr;
  1652.     SHORT ReturnCode;
  1653.     LONG offset = 0;
  1654.  
  1655.     if (soundFile == 0)
  1656.         return;
  1657.     if (soundFile[0] == 0) {
  1658.         WinAlarm( HWND_DESKTOP, WA_NOTE );
  1659.         return;
  1660.         }
  1661.  
  1662.     MakeHourglassPointer ();                       // switch to hourglass cursor
  1663.     offset += sprintf(mesg+offset, "/* */\r\n");
  1664.     offset += sprintf(mesg+offset, "rc = call RxFuncAdd('mciRxInit','MCIAPI',,\r\n'mciRxInit')\r\n");
  1665.     offset += sprintf(mesg+offset, "rc = call mciRxInit()\r\n");
  1666.     offset += sprintf(mesg+offset, "rc = mciRxSendString('open waveaudio',\r\n'alias wave shareable wait',,\r\n'RetStr','0','0')\r\n");
  1667.     offset += sprintf(mesg+offset, "rc = mciRxSendString('load wave %s wait',,\r\n'RetStr','0','0')\r\n", soundFile );
  1668.     offset += sprintf(mesg+offset, "rc = mciRxSendString('play wave wait',,\r\n'RetStr','0','0')\r\n" );
  1669.     offset += sprintf(mesg+offset, "rc = mciRxSendString('close wave wait',,\r\n'RetStr','0','0')\r\n" );
  1670.     offset += sprintf(mesg+offset, "call mciRxExit\r\n" );
  1671.     sprintf(mesg+offset, "exit\r\n\x1A\0" );
  1672.  
  1673.     INSTORE[0].strptr=mesg;
  1674.     INSTORE[0].strlength=strlen(mesg);
  1675.     INSTORE[1].strptr=NULL;
  1676.     INSTORE[1].strlength=0;
  1677.  
  1678.     rc = rexxStart((LONG)0,
  1679.               (PRXSTRING)0,
  1680.               (PSZ)LAUNCHFILE,
  1681.               (PRXSTRING)INSTORE,
  1682.               (PSZ)"CMD",
  1683.               (LONG)RXCOMMAND,
  1684.               (PRXSYSEXIT)0,
  1685.               (SHORT*)&ReturnCode,
  1686.               (PRXSTRING)&retstr);
  1687.  
  1688.     // if there was an error (ie: no MMPM), make a system beep
  1689.     if (rc)
  1690.         WinAlarm( HWND_DESKTOP, WA_NOTE );
  1691.  
  1692.     MakeArrowPointer ();                      // switch back to arrow pointer,
  1693. }
  1694.  
  1695.  
  1696. ////////////////////////////////////////////////////////////////////////////////
  1697. // update the time displayed on the FileBar menubar
  1698. ////////////////////////////////////////////////////////////////////////////////
  1699. VOID updateTimeDisplay( HWND window ) {
  1700.     MENUITEM itemData;
  1701.     char tmp1[24];
  1702.     char tmp2[24];
  1703.     CHAR buffer[64] = { '\0' };
  1704.     struct tm *time_now;
  1705.     time_t currentTime;
  1706.  
  1707.     tzset();
  1708.     time(¤tTime);
  1709.     time_now = localtime( ¤tTime );
  1710.  
  1711.     if ((timeOption == TIMEONLY) || (timeOption == TIMEANDDATE)) {
  1712.         strftime( tmp1, sizeof(tmp1), "%I", time_now);
  1713.         strftime( tmp2, sizeof(tmp2), ":%M %p  ", time_now);
  1714.         if (tmp1[0] == '0')
  1715.             tmp1[0]=' ';
  1716.         strcat( buffer, tmp1 );
  1717.         strcat( buffer, tmp2 );
  1718.         }
  1719.     if (timeOption == TIMEANDDATE)
  1720.         strcat( buffer, " " );
  1721.     if ((timeOption == DATEONLY) || (timeOption == TIMEANDDATE)) {
  1722.         strftime( tmp1, sizeof(tmp1), "%B", time_now);
  1723.         strftime( tmp2, sizeof(tmp2), "%d, %Y  ", time_now);
  1724.  
  1725.         if (tmp2[0] == '0') {
  1726.             tmp2[0] = ' ';
  1727.             strcat( buffer, tmp1 );
  1728.             strcat( buffer, tmp2 );
  1729.             }
  1730.         else {
  1731.             strcat( buffer, tmp1 );
  1732.             strcat( buffer, " \0" );
  1733.             strcat( buffer, tmp2 );
  1734.             }
  1735.         }
  1736.     else if (timeOption == OTHERTIMEONLY)
  1737.         strftime( buffer, sizeof(buffer), "%H:%M  ", time_now);
  1738.     else if (timeOption == OTHERDATEONLY)
  1739.         strftime( buffer, sizeof(buffer), "%d %B %Y  ", time_now);
  1740.     else if (timeOption == OTHERTIMEANDDATE) {
  1741.         strftime( tmp1, sizeof(tmp1), "%H:%M ", time_now );
  1742.         strftime( tmp2, sizeof(tmp2), "%d %B %Y  ", time_now );
  1743.         if (tmp1[0] == '0')
  1744.             tmp1[0] = ' ';
  1745.         if (tmp2[0] == '0')
  1746.             tmp2[0] = ' ';
  1747.         else
  1748.             strcat( tmp1, " " );
  1749.         strcat( buffer, tmp1 );
  1750.         strcat( buffer, tmp2 );
  1751.         }
  1752.     if (buffer[0]=='0')
  1753.         buffer[0]=' ';
  1754.  
  1755.  
  1756.     // this code was changed since IBM changed the way button separators
  1757.     // work in Warp.  Now, button separator text cannot be changed.  So, before
  1758.     // I change it, I change the menu item back to a normal menu item, change
  1759.     // the item and then change it back.
  1760.     if (RunningWarp) {
  1761.         WinEnableWindowUpdate( window, FALSE );
  1762.         WinSendMsg( window, MM_QUERYITEM, MPFROM2SHORT(TIMEDATE,TRUE), MPFROMP(&itemData) );
  1763.         itemData.afStyle = MIS_TEXT;
  1764.         WinSendMsg( window, MM_SETITEM, MPFROM2SHORT(TIMEDATE,TRUE), MPFROMP(&itemData) );
  1765.  
  1766.         WinSetMenuItemText( window, TIMEDATE, buffer );
  1767.  
  1768.         itemData.afStyle = MIS_TEXT|MIS_BUTTONSEPARATOR;
  1769.         WinSendMsg( window, MM_SETITEM, MPFROM2SHORT(TIMEDATE,TRUE), MPFROMP(&itemData) );
  1770.         WinEnableWindowUpdate( window, TRUE );
  1771.         WinUpdateWindow( window );
  1772.         }
  1773.     else
  1774.         WinSetMenuItemText( window, TIMEDATE, buffer );
  1775. }
  1776.  
  1777.  
  1778. ////////////////////////////////////////////////////////////////////////////////
  1779. // displayTimeDate is used to check to see if time/date on the FileBar menu
  1780. // needs updateing and also to check to see if any alarms need to be serviced
  1781. ////////////////////////////////////////////////////////////////////////////////
  1782. VOID displayTimeDate( VOID )
  1783. {
  1784.     struct tm *time_now;
  1785.     time_t currentTime;
  1786.  
  1787.     tzset();
  1788.     time(¤tTime);
  1789.     time_now = localtime( ¤tTime );
  1790.  
  1791.  
  1792.     if (timeOption != NONE)
  1793.         if (((timeOption != DATEONLY) && (timeOption != OTHERDATEONLY)) ||
  1794.              (time_now->tm_min == 0) )
  1795.             updateTimeDisplay( hwndMenu );
  1796.  
  1797.     if (time_now->tm_min == 30)
  1798.         alreadyChimed = FALSE;
  1799.  
  1800.     if ((!alreadyChimed) && (time_now->tm_min == 0) && (HourlyChime)) {
  1801.         alreadyChimed = TRUE;
  1802.         ringChime( hourlyChimeWavFile );
  1803.         }
  1804.  
  1805.     checkAlarms( time_now->tm_hour, time_now->tm_min, time_now->tm_mon,
  1806.                  time_now->tm_mday, time_now->tm_year );
  1807. }
  1808.  
  1809.  
  1810. ////////////////////////////////////////////////////////////////////////////////
  1811. // resets the file dialog control structure so its OK to use next time
  1812. ////////////////////////////////////////////////////////////////////////////////
  1813. VOID resetFileDialog( VOID )
  1814. {
  1815.     SHORT s;
  1816.  
  1817.     s=strlen(fileDlgInfo.szFullFile);
  1818.     while((fileDlgInfo.szFullFile[s]!='\\') && (s>=0))
  1819.         s--;
  1820.  
  1821.     if (fileDlgInfo.szFullFile[s]=='\\')
  1822.         fileDlgInfo.szFullFile[s+1]='\0';
  1823.     else
  1824.         fileDlgInfo.szFullFile[0]='\0';
  1825. }
  1826.  
  1827. ////////////////////////////////////////////////////////////////////////////////
  1828. // Message handler for time and date option setting dialog
  1829. ////////////////////////////////////////////////////////////////////////////////
  1830. MRESULT EXPENTRY TimeDateProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  1831. {
  1832.    switch( msg )
  1833.     {
  1834.         //----------------------------------------------------------------------
  1835.         // when the dialog is being initialized, center it on desktop and check
  1836.         // the appropriate radio button for whatever setting they currently have
  1837.         //----------------------------------------------------------------------
  1838.         case WM_INITDLG: {
  1839.             SWP swp;
  1840.  
  1841.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  1842.             WinSetWindowPos( hWnd, (HWND)0,
  1843.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  1844.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  1845.                              0, 0, SWP_MOVE);
  1846.             WinSendDlgItemMsg( hWnd, timeOption, BM_SETCHECK,
  1847.                                MPFROM2SHORT( 1, 0 ), 0);
  1848.             WinCheckButton( hWnd, PLAYCHIME, HourlyChime );
  1849.  
  1850.             WinSendDlgItemMsg( hWnd, CHIMEWAVFILE, EM_SETTEXTLIMIT,
  1851.                                MPFROM2SHORT( MAXACTIONSTRINGLENGTH-1, 0 ), 0 );
  1852.             WinSetDlgItemText( hWnd, CHIMEWAVFILE, hourlyChimeWavFile);
  1853.  
  1854.             break;
  1855.             }
  1856.         //----------------------------------------------------------------------
  1857.         // we received a change in control, update menubar time
  1858.         //----------------------------------------------------------------------
  1859.         case WM_CONTROL:
  1860.         {
  1861.             timeOption = NONE;
  1862.             if (WinQueryButtonCheckstate( hWnd, TIMEONLY ))
  1863.                 timeOption = TIMEONLY;
  1864.             else if (WinQueryButtonCheckstate( hWnd, DATEONLY ))
  1865.                 timeOption = DATEONLY;
  1866.             else if (WinQueryButtonCheckstate( hWnd, TIMEANDDATE ))
  1867.                 timeOption = TIMEANDDATE;
  1868.             else if (WinQueryButtonCheckstate( hWnd, OTHERTIMEONLY ))
  1869.                 timeOption = OTHERTIMEONLY;
  1870.             else if (WinQueryButtonCheckstate( hWnd, OTHERDATEONLY ))
  1871.                 timeOption = OTHERDATEONLY;
  1872.             else if (WinQueryButtonCheckstate( hWnd, OTHERTIMEANDDATE ))
  1873.                 timeOption = OTHERTIMEANDDATE;
  1874.  
  1875.             WinStopTimer( hab, hwndClient, timerNumber );
  1876.             restartTimer();
  1877.             updateTimeDisplay( hwndMenu );
  1878.             break;
  1879.         }
  1880.  
  1881.         //----------------------------------------------------------------------
  1882.         // if we receive any system message, dismiss dialog and store new option
  1883.         //----------------------------------------------------------------------
  1884.         case WM_COMMAND:
  1885.         {
  1886.             USHORT command = SHORT1FROMMP(mp1);
  1887.             switch( command ) {
  1888.             case TESTWAVEFILE: {
  1889.                 WinQueryDlgItemText( hWnd, CHIMEWAVFILE, sizeof(hourlyChimeWavFile), hourlyChimeWavFile);
  1890.                 ringChime( hourlyChimeWavFile );
  1891.                 return 0;
  1892.                 }
  1893.             case FINDWAVFILE: {
  1894.                 CHAR title[] = MSG18;
  1895.                 HWND hwndDialog;
  1896.  
  1897.                 fileDlgInfo.fl = FDS_OPEN_DIALOG|FDS_CENTER;
  1898.                 fileDlgInfo.pszTitle = title;
  1899.  
  1900.                 strcpy(oldDirectory, fileDlgInfo.szFullFile);
  1901.                 strcat(fileDlgInfo.szFullFile, "*.WAV\0");
  1902.  
  1903.                 hwndDialog = WinFileDlg( HWND_DESKTOP, hWnd, &fileDlgInfo );
  1904.                 if (hwndDialog && (fileDlgInfo.lReturn == DID_OK)) {
  1905.                     strcpy( hourlyChimeWavFile, fileDlgInfo.szFullFile );
  1906.                     resetFileDialog();
  1907.                     WinSetDlgItemText( hWnd, CHIMEWAVFILE, hourlyChimeWavFile );
  1908.                     }
  1909.                 else
  1910.                     strcpy(fileDlgInfo.szFullFile, oldDirectory);
  1911.                 return 0;
  1912.                 }
  1913.             }
  1914.  
  1915.             timeOption = NONE;
  1916.             if (WinQueryButtonCheckstate( hWnd, TIMEONLY ))
  1917.                 timeOption = TIMEONLY;
  1918.             else if (WinQueryButtonCheckstate( hWnd, DATEONLY ))
  1919.                 timeOption = DATEONLY;
  1920.             else if (WinQueryButtonCheckstate( hWnd, TIMEANDDATE ))
  1921.                 timeOption = TIMEANDDATE;
  1922.             else if (WinQueryButtonCheckstate( hWnd, OTHERTIMEONLY ))
  1923.                 timeOption = OTHERTIMEONLY;
  1924.             else if (WinQueryButtonCheckstate( hWnd, OTHERDATEONLY ))
  1925.                 timeOption = OTHERDATEONLY;
  1926.             else if (WinQueryButtonCheckstate( hWnd, OTHERTIMEANDDATE ))
  1927.                 timeOption = OTHERTIMEANDDATE;
  1928.  
  1929.             HourlyChime = WinQueryButtonCheckstate( hWnd, PLAYCHIME );
  1930.  
  1931.             // stop current timer (if one exists) and start a new one
  1932.             // display new time and date according to new option setting
  1933.             WinStopTimer( hab, hwndClient, timerNumber );
  1934.             restartTimer();
  1935.             WinQueryDlgItemText( hWnd, CHIMEWAVFILE, sizeof(hourlyChimeWavFile), hourlyChimeWavFile);
  1936.             WinDismissDlg( hWnd, TRUE );
  1937.             return 0;
  1938.         }
  1939.         //----------------------------------------------------------------------
  1940.         // if nothing further we want to intercept, pass message onto system
  1941.         //----------------------------------------------------------------------
  1942.         default:
  1943.             break;
  1944.     }
  1945.     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  1946. }
  1947.  
  1948.  
  1949. ////////////////////////////////////////////////////////////////////////////////
  1950. // EditMenuProc - the message handler for editing a menu dialog box
  1951. ////////////////////////////////////////////////////////////////////////////////
  1952. MRESULT EXPENTRY EditMenuProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  1953. {
  1954.     switch( msg )
  1955.     {
  1956.         //----------------------------------------------------------------------
  1957.         // if double-clicked an entry, allow them to edit it
  1958.         //----------------------------------------------------------------------
  1959.         case WM_CONTROL:
  1960.         {
  1961.             if ((SHORT1FROMMP(mp1)==CURMENULIST) && (SHORT2FROMMP(mp1)==LN_ENTER))
  1962.                 return WinSendMsg( hWnd, WM_COMMAND, MPFROM2SHORT( EDITMENUBUTTON, 0 ), mp2 );
  1963.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  1964.         }
  1965.         //----------------------------------------------------------------------
  1966.         // when the dialog is being initialized, center it on desktop and put
  1967.         // the current data into appropriate list boxes
  1968.         //----------------------------------------------------------------------
  1969.         case WM_INITDLG: {
  1970.             SWP swp;
  1971.  
  1972.             for (short i=0; i<NumMenus; i++)
  1973.                 WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
  1974.                                    MPFROM2SHORT( LIT_END, 0 ),
  1975.                                    MenuName[i] );
  1976.             if (NumMenus > 0) {
  1977.                 WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  1978.                                    MPFROM2SHORT( 0, 0 ),
  1979.                                    MPFROM2SHORT( TRUE, 0 ) );
  1980.                 }
  1981.             else {
  1982.                 WinEnableControl( hWnd, EDITMENUBUTTON, FALSE );
  1983.                 WinEnableControl( hWnd, REMOVEMENU, FALSE );
  1984.                 WinEnableControl( hWnd, MOVEMENULEFT, FALSE );
  1985.                 WinEnableControl( hWnd, MOVEMENURIGHT, FALSE );
  1986.                 }
  1987.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  1988.             WinSetWindowPos( hWnd, (HWND)0,
  1989.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  1990.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  1991.                              0, 0, SWP_MOVE);
  1992.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  1993.             }
  1994.         //----------------------------------------------------------------------
  1995.         // process a command message received from the system
  1996.         //----------------------------------------------------------------------
  1997.         case WM_COMMAND: {
  1998.             USHORT command = SHORT1FROMMP(mp1);
  1999.             switch( command )
  2000.                 {
  2001.                 //--------------------------------------------------------------
  2002.                 // if they pressed OK button, dismiss dialog and return
  2003.                 //--------------------------------------------------------------
  2004.                 case DID_OK: {
  2005.                     WinDismissDlg( hWnd, TRUE );
  2006.                     return 0;
  2007.                     }
  2008.                 //--------------------------------------------------------------
  2009.                 // they want to edit a menu
  2010.                 //--------------------------------------------------------------
  2011.                 case EDITMENUBUTTON: {
  2012.                     if (NumMenus == 0) {
  2013.                         WinAlarm(HWND_DESKTOP, WA_ERROR);
  2014.                         return 0;
  2015.                         }
  2016.                     // find out what menu they've selected in list box
  2017.                     MenuSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
  2018.                                                                      LM_QUERYSELECTION,
  2019.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  2020.                                                                      0 ) );
  2021.                     // display edit menu dialog box
  2022.                     WinDlgBox(HWND_DESKTOP,
  2023.                               hWnd,
  2024.                               (PFNWP)EditItemProc,
  2025.                               0,
  2026.                               EDITITEM,
  2027.                               (PVOID)NULL);
  2028.                     // change the item in the list box and select it
  2029.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEALL, 0, 0 );
  2030.                     for (short i=0; i<NumMenus; i++)
  2031.                         WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
  2032.                                            MPFROM2SHORT( LIT_END, 0 ),
  2033.                                            MenuName[i] );
  2034.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  2035.                                        MPFROM2SHORT( MenuSelection, 0 ),
  2036.                                        MPFROM2SHORT( TRUE, 0 ) );
  2037.                     return 0;
  2038.                     }
  2039.                 //--------------------------------------------------------------
  2040.                 // the user wants to add another menu to the menubar
  2041.                 //--------------------------------------------------------------
  2042.                 case ADDMENU: {
  2043.                     MenuSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
  2044.                                                                      LM_QUERYSELECTION,
  2045.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  2046.                                                                      0 ) );
  2047.                     // error if no room for another menu
  2048.                     if (NumMenus >= MAXMENUS) {
  2049.                         WinMessageBox( HWND_DESKTOP, hWnd,
  2050.                                        MSG19, MSG20, 0,
  2051.                                        MB_MOVEABLE|MB_ERROR|MB_OK);
  2052.                         return 0;
  2053.                         }
  2054.                     WinDlgBox(HWND_DESKTOP,
  2055.                               hWnd,
  2056.                               (PFNWP)AddAMenuProc,
  2057.                               0,
  2058.                               ADDAMENU,
  2059.                               (PVOID)NULL);
  2060.                     // if first menu to be added, enable buttons
  2061.                     if (NumMenus > 0) {
  2062.                         WinEnableControl( hWnd, EDITMENUBUTTON, TRUE );
  2063.                         WinEnableControl( hWnd, REMOVEMENU, TRUE );
  2064.                         WinEnableControl( hWnd, MOVEMENULEFT, TRUE );
  2065.                         WinEnableControl( hWnd, MOVEMENURIGHT, TRUE );
  2066.                         }
  2067.  
  2068.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEALL, 0, 0 );
  2069.                     for (short i=0; i<NumMenus; i++)
  2070.                         WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
  2071.                                            MPFROM2SHORT( LIT_END, 0 ),
  2072.                                            MenuName[i] );
  2073.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  2074.                                        MPFROM2SHORT( MenuSelection, 0 ),
  2075.                                        MPFROM2SHORT( TRUE, 0 ) );
  2076.                     return 0;
  2077.                     }
  2078.                 //--------------------------------------------------------------
  2079.                 // the user wants to remove a menu from the menu list box
  2080.                 //--------------------------------------------------------------
  2081.                 case REMOVEMENU: {
  2082.                     if (NumMenus == 0) {
  2083.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  2084.                         return 0;
  2085.                         }
  2086.  
  2087.                     if (NumMenus > 0)
  2088.                         if (WinMessageBox( HWND_DESKTOP, hWnd,
  2089.                                            MSG21,
  2090.                                            MSG22, 0,
  2091.                                            MB_MOVEABLE|MB_WARNING|MB_YESNO|MB_DEFBUTTON2) == MBID_YES ) {
  2092.                             short index = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
  2093.                                                                            LM_QUERYSELECTION,
  2094.                                                                            MPFROM2SHORT( LIT_FIRST, 0 ),
  2095.                                                                            0 ) );
  2096.                             MENUITEM menuItem;
  2097.  
  2098.                             // delete it from the list box
  2099.                             WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEITEM,
  2100.                                                MPFROM2SHORT( index, 0 ), 0 );
  2101.  
  2102.                             // delete it from menu structure
  2103.                             MakeHourglassPointer ();
  2104.                             WinSetMenuItemText( hwndMenu, 100*index+100, "" );
  2105.                             for (short i=index+1; i<MAXMENUS; i++)
  2106.                                 SwapTwoMenus( i-1, i );
  2107.  
  2108.                             ////////////////////////////////////////////////////
  2109.                             for (i=0; i<NumItems[MAXMENUS-1]; i++)
  2110.                                 delete Menus[MAXMENUS-1][i];
  2111.                             ////////////////////////////////////////////////////
  2112.                             NumItems[MAXMENUS-1] = 0;
  2113.                             MenuName[MAXMENUS-1][0] = '\0';
  2114.                             if (NumMenus > 0) {
  2115.                                 int newIndex = index-1;
  2116.                                 if (0 > newIndex)
  2117.                                     newIndex = 0;
  2118.  
  2119.                                 if (index == NumMenus-1)
  2120.                                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  2121.                                                        MPFROM2SHORT( newIndex, 0 ),
  2122.                                                        MPFROM2SHORT( TRUE, 0 ) );
  2123.                                 else
  2124.                                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  2125.                                                        MPFROM2SHORT( index, 0 ),
  2126.                                                        MPFROM2SHORT( TRUE, 0 ) );
  2127.                                 }
  2128.                             WinSendMsg( hwndMenu, MM_QUERYITEM, MPFROM2SHORT(NumMenus*100,TRUE),MPFROMP(&menuData[index]));
  2129.                             menuItem = menuData[index];
  2130.                             menuItem.afStyle = MIS_STATIC;
  2131.                             menuItem.afAttribute = MIA_DISABLED;
  2132.                             WinSendMsg( hwndMenu, MM_SETITEM, MPFROM2SHORT(NumMenus*100,TRUE),MPFROMP(&menuItem));
  2133.                             WinSetMenuItemText( hwndMenu, 100*MAXMENUS, "" );
  2134.                             NumItems[ NumMenus ] = 0;
  2135.                             NumMenus--;
  2136.  
  2137.                             // if we deleted only menu, disable menu buttons
  2138.                             if (NumMenus == 0) {
  2139.                                 WinEnableControl( hWnd, EDITMENUBUTTON, FALSE );
  2140.                                 WinEnableControl( hWnd, REMOVEMENU, FALSE );
  2141.                                 WinEnableControl( hWnd, MOVEMENULEFT, FALSE );
  2142.                                 WinEnableControl( hWnd, MOVEMENURIGHT, FALSE );
  2143.                                 }
  2144.                             MakeArrowPointer ();
  2145.                             }
  2146.                     return 0;
  2147.                     }
  2148.                 //--------------------------------------------------------------
  2149.                 // move menu left in menu structure
  2150.                 //--------------------------------------------------------------
  2151.                 case MOVEMENULEFT: {
  2152.                     short index = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
  2153.                                                              LM_QUERYSELECTION,
  2154.                                                              MPFROM2SHORT( LIT_FIRST, 0 ),
  2155.                                                              0 ) );
  2156.                     if ((NumMenus == 0) || (index == 0)) {
  2157.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  2158.                         return 0;
  2159.                         }
  2160.                     MakeHourglassPointer ();
  2161.                     SwapTwoMenus( index-1, index );
  2162.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEITEM,
  2163.                                        MPFROM2SHORT( index, 0 ), 0 );
  2164.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
  2165.                                        MPFROM2SHORT( index-1, 0 ), MenuName[index-1] );
  2166.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  2167.                                        MPFROM2SHORT( index-1, 0 ),
  2168.                                        MPFROM2SHORT( TRUE, 0 ) );
  2169.                     MakeArrowPointer ();
  2170.                     return 0;
  2171.                     }
  2172.                 //--------------------------------------------------------------
  2173.                 // move menu right in menu structure
  2174.                 //--------------------------------------------------------------
  2175.                 case MOVEMENURIGHT: {
  2176.                     short index = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
  2177.                                                              LM_QUERYSELECTION,
  2178.                                                              MPFROM2SHORT( LIT_FIRST, 0 ),
  2179.                                                              0 ) );
  2180.                     if ((NumMenus == 0) || (index == (NumMenus)-1)) {
  2181.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  2182.                         return 0;
  2183.                         }
  2184.                     SwapTwoMenus( index, index+1 );
  2185.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEITEM,
  2186.                                        MPFROM2SHORT( index, 0 ), 0 );
  2187.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
  2188.                                        MPFROM2SHORT( index+1, 0 ), MenuName[index+1] );
  2189.                     WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
  2190.                                        MPFROM2SHORT( index+1, 0 ),
  2191.                                        MPFROM2SHORT( TRUE, 0 ) );
  2192.                     return 0;
  2193.                     }
  2194.                 //--------------------------------------------------------------
  2195.                 // nothing we care about, pass it onto the system default proc
  2196.                 //--------------------------------------------------------------
  2197.                 default:
  2198.                     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2199.                 }
  2200.             }
  2201.         //----------------------------------------------------------------------
  2202.         // if nothing further we want to intercept, pass message onto system
  2203.         //----------------------------------------------------------------------
  2204.         default:
  2205.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2206.     }
  2207. }
  2208.  
  2209.  
  2210. ////////////////////////////////////////////////////////////////////////////////
  2211. // SwapTwoMenus will swap the FileBar stored information entries for two menus
  2212. // indicated by menu1 and menu2.  The text on the displayed menubar will also
  2213. // be changed to indicate the swap.
  2214. ////////////////////////////////////////////////////////////////////////////////
  2215. void SwapTwoMenus( short menu1, short menu2 )
  2216. {
  2217.     USERMENUITEM* tmpPtr;
  2218.     BYTE t2;
  2219.  
  2220.     for (short i=0; i<MAXITEMS; i++) {
  2221.         tmpPtr = Menus[menu1][i];
  2222.         Menus[menu1][i] = Menus[menu2][i];
  2223.         Menus[menu2][i] = tmpPtr;
  2224.         }
  2225.  
  2226.     t2 = NumItems[menu2];
  2227.     NumItems[menu2] = NumItems[menu1];
  2228.     NumItems[menu1] = t2;
  2229.  
  2230.     strcpy( tmpBuffer, MenuName[menu1] );
  2231.     strcpy( MenuName[menu1], MenuName[menu2] );
  2232.     strcpy( MenuName[menu2], tmpBuffer );
  2233.  
  2234.     WinSetMenuItemText( hwndMenu, 100+menu1*100, MenuName[menu1] );
  2235.     WinSetMenuItemText( hwndMenu, 100+menu2*100, MenuName[menu2] );
  2236. }
  2237.  
  2238.  
  2239. ////////////////////////////////////////////////////////////////////////////////
  2240. // AddAMenuProc - message handler for the dialog box that allows the user to
  2241. // add a menu to the menubar
  2242. ////////////////////////////////////////////////////////////////////////////////
  2243. MRESULT EXPENTRY AddAMenuProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2244. {
  2245.    switch( msg )
  2246.     {
  2247.         //----------------------------------------------------------------------
  2248.         // when the dialog is being initialized, center it on desktop and put
  2249.         // the current data into controls
  2250.         //----------------------------------------------------------------------
  2251.         case WM_INITDLG: {
  2252.             SWP swp;
  2253.             WinSendDlgItemMsg( hWnd, MENUNAME, EM_SETTEXTLIMIT,
  2254.                                MPFROM2SHORT( MAXMENUNAMELENGTH-1, 0 ), 0 );
  2255.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  2256.             WinSetWindowPos( hWnd, (HWND)0,
  2257.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  2258.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  2259.                              0, 0, SWP_MOVE);
  2260.             break;
  2261. //            return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2262.             }
  2263.         //----------------------------------------------------------------------
  2264.         // process a command message received from the system
  2265.         //----------------------------------------------------------------------
  2266.         case WM_COMMAND:
  2267.         {
  2268.             USHORT command = SHORT1FROMMP(mp1);
  2269.             switch( command )
  2270.                 {
  2271.                 //--------------------------------------------------------------
  2272.                 // user press OK button.  Add the menu name they entered into
  2273.                 // the menu structure and return
  2274.                 //--------------------------------------------------------------
  2275.                 case DID_OK: {
  2276.                     WinQueryDlgItemText( hWnd, MENUNAME, MAXMENUNAMELENGTH, MenuName[NumMenus]);
  2277.                     NumItems[NumMenus] = 0;
  2278.                     menuData[NumMenus].afStyle = 0;
  2279.                     menuData[NumMenus].afAttribute = 0;
  2280.                     WinSendMsg( hwndMenu, MM_SETITEM, MPFROM2SHORT(100*NumMenus+100,TRUE),MPFROMP(&menuData[NumMenus]));
  2281.                     WinSetMenuItemText( hwndMenu, 100*NumMenus+100, &MenuName[NumMenus]);
  2282.                     MenuSelection = NumMenus;
  2283.                     NumMenus++;
  2284.                     WinDismissDlg( hWnd, TRUE );
  2285.                     return 0;
  2286.                     }
  2287.                 //--------------------------------------------------------------
  2288.                 // they decided not to add a menu, dismiss dialog and return
  2289.                 //--------------------------------------------------------------
  2290.                 case DID_CANCEL: {
  2291.                     WinDismissDlg( hWnd, TRUE );
  2292.                     return 0;
  2293.                     }
  2294.                 //--------------------------------------------------------------
  2295.                 // nothing we care about, pass on for default processing
  2296.                 //--------------------------------------------------------------
  2297.                 default:
  2298.                     break;
  2299.                 }
  2300.         }
  2301.         // ---------------------------------------------------------------------
  2302.         // if nothing further we want to intercept, pass message onto system
  2303.         // ---------------------------------------------------------------------
  2304.         default:
  2305.             break;
  2306.     }
  2307.     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2308. }
  2309.  
  2310.  
  2311. ////////////////////////////////////////////////////////////////////////////////
  2312. // Swap menu items item1 and item2 on menu Menu in the menu information arrays
  2313. ////////////////////////////////////////////////////////////////////////////////
  2314. VOID SwapTwoItems(SHORT Menu, SHORT item1, SHORT item2)
  2315. {
  2316.     USERMENUITEM* tmpPtr;
  2317.  
  2318.     tmpPtr = Menus[Menu][item1];
  2319.     Menus[Menu][item1] = Menus[Menu][item2];
  2320.     Menus[Menu][item2] = tmpPtr;
  2321. }
  2322.  
  2323.  
  2324. ////////////////////////////////////////////////////////////////////////////////
  2325. // updateItemList - refreshes the contents of the item list list-box in a dialog
  2326. ////////////////////////////////////////////////////////////////////////////////
  2327. VOID updateItemList( HWND hWnd )
  2328. {
  2329.     CHAR Separator[] = SEPARATOR;
  2330.     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_DELETEALL, 0, 0 );
  2331.     for (short i=0; i<NumItems[MenuSelection]; i++)
  2332.         if (Menus[MenuSelection][i]->ItemName[0] != '\0')
  2333.             WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
  2334.                                MPFROM2SHORT( LIT_END, 0 ),
  2335.                                Menus[MenuSelection][i]->ItemName );
  2336.         else
  2337.             WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
  2338.                                MPFROM2SHORT( LIT_END, 0 ),
  2339.                                Separator );
  2340.     if (NumItems[MenuSelection] > 0)
  2341.         WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
  2342.                            MPFROM2SHORT( ItemSelection, 0 ),
  2343.                            MPFROM2SHORT( TRUE, 0 ) );
  2344. }
  2345.  
  2346.  
  2347. ////////////////////////////////////////////////////////////////////////////////
  2348. // EditItemProc - the message handler for the edit menu item dialog box
  2349. ////////////////////////////////////////////////////////////////////////////////
  2350. MRESULT EXPENTRY EditItemProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2351. {
  2352.     switch( msg )
  2353.     {
  2354.         //----------------------------------------------------------------------
  2355.         // when the dialog is being initialized, center it on desktop and put
  2356.         // the current data into control fields
  2357.         //----------------------------------------------------------------------
  2358.         case WM_INITDLG: {
  2359.             SWP swp;
  2360.             WinSendDlgItemMsg( hWnd, MENUNAME, EM_SETTEXTLIMIT,
  2361.                                MPFROM2SHORT( MAXMENUNAMELENGTH-1, 0 ), 0 );
  2362.             WinSetDlgItemText( hWnd, MENUNAME, MenuName[MenuSelection]);
  2363.             ItemSelection = 0;
  2364.             updateItemList( hWnd );
  2365.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  2366.             WinSetWindowPos( hWnd, (HWND)0,
  2367.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  2368.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  2369.                              0, 0, SWP_MOVE);
  2370.             break;
  2371. //            return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2372.             }
  2373.         //----------------------------------------------------------------------
  2374.         // if there is a control message, update enabled status of buttons
  2375.         //----------------------------------------------------------------------
  2376.         case WM_CONTROL:
  2377.         {
  2378.             if ((SHORT1FROMMP(mp1)==ITEMMENU) && (SHORT2FROMMP(mp1)==LN_ENTER))
  2379.                 return WinSendMsg( hWnd, WM_COMMAND, MPFROM2SHORT( CHANGEITEM, 0 ), mp2 );
  2380.             break;
  2381. //            return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2382.         }
  2383.         //----------------------------------------------------------------------
  2384.         // process a command message received from the system
  2385.         //----------------------------------------------------------------------
  2386.         case WM_COMMAND:
  2387.         {
  2388.             USHORT command = SHORT1FROMMP(mp1);
  2389.             switch( command )
  2390.                 {
  2391.                 //--------------------------------------------------------------
  2392.                 // insert a separator into item list, if there is room
  2393.                 //--------------------------------------------------------------
  2394.                 case INSERTSEPARATOR: {
  2395.                     ItemSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
  2396.                                                                      LM_QUERYSELECTION,
  2397.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  2398.                                                                      0 ) );
  2399.                     if (NumItems[MenuSelection] >= MAXITEMS-1) {
  2400.                         // error and return if no room
  2401.                         WinMessageBox( HWND_DESKTOP, hWnd,
  2402.                                        MSG23, MSG24, 0,
  2403.                                        MB_MOVEABLE|MB_ERROR|MB_OK);
  2404.                         return 0;
  2405.                         }
  2406.  
  2407.                     // since this is a separator, blank out launch information
  2408.                     ItemSelection = 0;
  2409.                     if (NumItems[MenuSelection] > 0)
  2410.                         for (short i=NumItems[MenuSelection]-1; i>=0; i--)
  2411.                             SwapTwoItems( MenuSelection, i, i+1 );
  2412.  
  2413.                     Menus[MenuSelection][ItemSelection] = new USERMENUITEM;
  2414.                     Menus[MenuSelection][ItemSelection]->ItemName[0]='\0';
  2415.                     NumItems[MenuSelection]++;
  2416. //                    UpdateMenu[MenuSelection] = TRUE;
  2417.                     updateItemList( hWnd );
  2418.                     return 0;
  2419.                     }
  2420.                 //--------------------------------------------------------------
  2421.                 // user wants to add an item to the current menu
  2422.                 //--------------------------------------------------------------
  2423.                 case ADDITEM: {
  2424.                     ItemSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
  2425.                                                                      LM_QUERYSELECTION,
  2426.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  2427.                                                                      0 ) );
  2428.                     // error and return if no room for another item
  2429.                     if (NumItems[MenuSelection] >= MAXITEMS) {
  2430.                         WinMessageBox( HWND_DESKTOP, hWnd,
  2431.                                        MSG25,
  2432.                                        MSG26, 0,
  2433.                                        MB_MOVEABLE|MB_ERROR|MB_OK);
  2434.                         return 0;
  2435.                         }
  2436.  
  2437.                     Menus[MenuSelection][ (NumItems[MenuSelection]) ] = new USERMENUITEM;
  2438.                     USERMENUITEM* menuItem = Menus[MenuSelection][ (NumItems[MenuSelection]) ];
  2439.                     strcpy( menuItem->ItemName, "Menu Item\0" );
  2440.                     menuItem->ActionToDo[0] = '\0';
  2441.                     menuItem->CmdLnArgs[0] = '\0';
  2442.                     menuItem->Directory[0] = '\0';
  2443.                     menuItem->ProgType = PM;
  2444.                     ItemSelection = NumItems[MenuSelection];
  2445.                     NumItems[MenuSelection]++;
  2446.                     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, FALSE,
  2447.                                       allowPopUpMenu, popUpMessageID );
  2448.                     WinDlgBox(HWND_DESKTOP,
  2449.                               hWnd,
  2450.                               (PFNWP)EditItemDataProc,
  2451.                               0,
  2452.                               EDITITEMDATA,
  2453.                               (PVOID)NULL);
  2454.                     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  2455.                                       allowPopUpMenu, popUpMessageID );
  2456.  
  2457.                     // update item list with possible new item
  2458.                     updateItemList( hWnd );
  2459.                     return 0;
  2460.                     }
  2461.                 //--------------------------------------------------------------
  2462.                 // user wants to change a menu item
  2463.                 //--------------------------------------------------------------
  2464.                 case CHANGEITEM: {
  2465.                     ItemSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
  2466.                                                                      LM_QUERYSELECTION,
  2467.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  2468.                                                                      0 ) );
  2469.                     if ((NumItems[MenuSelection] == 0) || (Menus[MenuSelection][ItemSelection]->ItemName[0] == '\0')) {
  2470.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  2471.                         return 0;
  2472.                         }
  2473.                     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, FALSE,
  2474.                                       allowPopUpMenu, popUpMessageID );
  2475.                     WinDlgBox(HWND_DESKTOP,
  2476.                               hWnd,
  2477.                               (PFNWP)EditItemDataProc,
  2478.                               0,
  2479.                               EDITITEMDATA,
  2480.                               (PVOID)NULL);
  2481.                     setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  2482.                                       allowPopUpMenu, popUpMessageID );
  2483.                     updateItemList( hWnd );
  2484.                     return 0;
  2485.                     }
  2486.                 //--------------------------------------------------------------
  2487.                 // move item down in menu order
  2488.                 //--------------------------------------------------------------
  2489.                 case MOVEITEMDOWN: {
  2490.                     CHAR Separator[] = SEPARATOR;
  2491.                     short i = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
  2492.                                                                LM_QUERYSELECTION,
  2493.                                                                MPFROM2SHORT( LIT_FIRST, 0 ),
  2494.                                                                0 ) );
  2495.                     if ((i == NumItems[MenuSelection]-1) || (NumItems[MenuSelection] == 0)) {
  2496.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  2497.                         return 0;
  2498.                         }
  2499.                     SwapTwoItems( MenuSelection, i, i+1 );
  2500.                     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_DELETEITEM,
  2501.                                        MPFROM2SHORT( i, 0 ),
  2502.                                        MPFROM2SHORT( TRUE, 0 ) );
  2503.                     if (Menus[MenuSelection][i+1]->ItemName[0] == '\0')
  2504.                         WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
  2505.                                            MPFROM2SHORT( i+1, 0 ),
  2506.                                            Separator );
  2507.                     else WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
  2508.                                             MPFROM2SHORT( i+1, 0 ),
  2509.                                             &Menus[MenuSelection][i+1]->ItemName );
  2510.                     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
  2511.                                        MPFROM2SHORT( i+1, 0 ),
  2512.                                        MPFROM2SHORT( TRUE, 0 ) );
  2513.                     return 0;
  2514.                     }
  2515.                 //--------------------------------------------------------------
  2516.                 // move item up in menu order
  2517.                 //--------------------------------------------------------------
  2518.                 case MOVEITEMUP: {
  2519.                     CHAR Separator[] = SEPARATOR;
  2520.                     short i = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
  2521.                                                                LM_QUERYSELECTION,
  2522.                                                                MPFROM2SHORT( LIT_FIRST, 0 ),
  2523.                                                                0 ) );
  2524.                     if ((i == 0) || (NumItems[MenuSelection] == 0)) {
  2525.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  2526.                         return 0;
  2527.                         }
  2528.                     SwapTwoItems( MenuSelection, i-1, i );
  2529.                     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_DELETEITEM,
  2530.                                        MPFROM2SHORT( i, 0 ),
  2531.                                        MPFROM2SHORT( TRUE, 0 ) );
  2532.                     if (Menus[MenuSelection][i-1]->ItemName[0] == '\0')
  2533.                         WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
  2534.                                            MPFROM2SHORT( i-1, 0 ),
  2535.                                            Separator );
  2536.                     else WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
  2537.                                             MPFROM2SHORT( i-1, 0 ),
  2538.                                             &Menus[MenuSelection][i-1]->ItemName );
  2539.                     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
  2540.                                        MPFROM2SHORT( i-1, 0 ),
  2541.                                        MPFROM2SHORT( TRUE, 0 ) );
  2542.                     return 0;
  2543.                     }
  2544.                 //--------------------------------------------------------------
  2545.                 // remove a menu item
  2546.                 //--------------------------------------------------------------
  2547.                 case REMOVEITEM: {
  2548.                     if (NumItems[MenuSelection] == 0) {
  2549.                         WinAlarm(HWND_DESKTOP, WA_WARNING);
  2550.                         return 0;
  2551.                         }
  2552.  
  2553.                     if (NumItems[MenuSelection] > 0)
  2554.                         if (WinMessageBox( HWND_DESKTOP, hWnd,
  2555.                                            MSG27,
  2556.                                            MSG28, 0,
  2557.                                            MB_MOVEABLE|MB_WARNING|MB_YESNO|MB_DEFBUTTON2) == MBID_YES ) {
  2558.                             short index = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
  2559.                                                                            LM_QUERYSELECTION,
  2560.                                                                            MPFROM2SHORT( LIT_FIRST, 0 ),
  2561.                                                                            0 ) );
  2562.                             WinSendDlgItemMsg( hWnd, ITEMMENU, LM_DELETEITEM,
  2563.                                                MPFROM2SHORT( index, 0 ), 0 );
  2564.  
  2565.                             delete Menus[MenuSelection][index];
  2566.                             for (short i=index; i<MAXITEMS-1; i++)
  2567.                                 Menus[MenuSelection][i] = Menus[MenuSelection][i+1];
  2568.  
  2569.                             if (NumItems[MenuSelection] > 0) {
  2570.                                 int newIndex = index-1;
  2571.                                 if (0 > newIndex)
  2572.                                     newIndex = 0;
  2573.  
  2574.                                 if (index == NumItems[MenuSelection]-1)
  2575.                                     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
  2576.                                                        MPFROM2SHORT( newIndex, 0 ),
  2577.                                                        MPFROM2SHORT( TRUE, 0 ) );
  2578.                                 else
  2579.                                     WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
  2580.                                                        MPFROM2SHORT( index, 0 ),
  2581.                                                        MPFROM2SHORT( TRUE, 0 ) );
  2582.                                 }
  2583.                             NumItems[MenuSelection]--;
  2584.                             }
  2585.                     return 0;
  2586.                     }
  2587.                 //--------------------------------------------------------------
  2588.                 // user is done editing a menu, save menu name and return
  2589.                 //--------------------------------------------------------------
  2590.                 case DID_OK: {
  2591.                     WinQueryDlgItemText( hWnd, MENUNAME, MAXMENUNAMELENGTH, MenuName[MenuSelection]);
  2592.                     WinSetMenuItemText( hwndMenu, 100*MenuSelection+100, &MenuName[MenuSelection]);
  2593.                     WinDismissDlg( hWnd, TRUE );
  2594.                     return 0;
  2595.                     }
  2596.                 //--------------------------------------------------------------
  2597.                 // not a message we care about, pass it onto the system
  2598.                 //--------------------------------------------------------------
  2599.                 default:
  2600.                     break;
  2601. //                    return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2602.                 }
  2603.         }
  2604.         //----------------------------------------------------------------------
  2605.         // if nothing further we want to intercept, pass message onto system
  2606.         //----------------------------------------------------------------------
  2607.         default:
  2608.            break;
  2609. //           return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2610.         }
  2611.     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2612. }
  2613.  
  2614.  
  2615. ////////////////////////////////////////////////////////////////////////////////
  2616. // update the enable/disabled state of the program type buttons
  2617. ////////////////////////////////////////////////////////////////////////////////
  2618. void updateEditItemWindow( HWND hWnd )
  2619. {
  2620.     SHORT value = TRUE;
  2621.  
  2622.     if (WinQueryButtonCheckstate( hWnd, STARTWPS ))
  2623.         value = FALSE;
  2624.  
  2625.     WinEnableControl( hWnd, MAXIMIZED, value );
  2626.     WinEnableControl( hWnd, MINIMIZED, value );
  2627.     WinEnableControl( hWnd, FOLDER, value );
  2628.     WinEnableControl( hWnd, DOSWIN, value );
  2629.     WinEnableControl( hWnd, DOSFS, value );
  2630.     WinEnableControl( hWnd, OS2WIN, value );
  2631.     WinEnableControl( hWnd, OS2FS, value );
  2632.     WinEnableControl( hWnd, WINOS2WIN, value );
  2633.     WinEnableControl( hWnd, WINOS2FS, value );
  2634.     WinEnableControl( hWnd, PMAPP, value );
  2635.     WinEnableControl( hWnd, SETTINGSBUTTON, TRUE-value );
  2636.  
  2637.     if (WinQueryButtonCheckstate( hWnd, FOLDER )) {
  2638.         WinEnableControl( hWnd, MAXIMIZED, FALSE );
  2639.         WinEnableControl( hWnd, MINIMIZED, FALSE );
  2640.         }
  2641.  
  2642.     if ((WinQueryButtonCheckstate( hWnd, FOLDER )) || (WinQueryButtonCheckstate( hWnd, PMAPP )))
  2643.         WinEnableControl( hWnd, STARTWPS, FALSE );
  2644.     else
  2645.         WinEnableControl( hWnd, STARTWPS, TRUE );
  2646.  
  2647.     if (Menus[MenuSelection][ItemSelection]->ActionToDo[0]=='\0')
  2648.         WinEnableControl( hWnd, SETTINGSBUTTON, FALSE );
  2649. }
  2650.  
  2651.  
  2652. ////////////////////////////////////////////////////////////////////////////////
  2653. // updateEditItemData - update the check states of all the buttons for the
  2654. // program item we are currently editing
  2655. ////////////////////////////////////////////////////////////////////////////////
  2656. void updateEditItemData( HWND hWnd )
  2657. {
  2658.     // put item name and length of longest possible name in entry field
  2659.     USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2660.  
  2661.     if ( Menus[MenuSelection][ItemSelection]->PasswordEnabled == YES )
  2662.         WinCheckButton( hWnd, PASSWORDPROTECT, TRUE );
  2663.     else WinCheckButton( hWnd, PASSWORDPROTECT, FALSE );
  2664.  
  2665.     WinSendDlgItemMsg( hWnd, ITEMNAME, EM_SETTEXTLIMIT,
  2666.                        MPFROM2SHORT( MAXITEMNAMELENGTH-1, 0 ), 0 );
  2667.     WinSetDlgItemText( hWnd, ITEMNAME, menuItem->ItemName);
  2668.     // put path name and length of longest possible name in entry field
  2669.     WinSendDlgItemMsg( hWnd, PATHNAME, EM_SETTEXTLIMIT,
  2670.                        MPFROM2SHORT( MAXACTIONSTRINGLENGTH-1, 0 ), 0 );
  2671.     WinSetDlgItemText( hWnd, PATHNAME, menuItem->ActionToDo);
  2672.     // put argument and length of longest possible in entry field
  2673.     WinSendDlgItemMsg( hWnd, ARGUMENTS, EM_SETTEXTLIMIT,
  2674.                        MPFROM2SHORT( MAXARGSTRINGLENGTH-1, 0 ), 0 );
  2675.     WinSetDlgItemText( hWnd, ARGUMENTS, menuItem->CmdLnArgs);
  2676.     // put directory and length of longest possible directory in entry field
  2677.     WinSendDlgItemMsg( hWnd, DIRECTORY, EM_SETTEXTLIMIT,
  2678.                        MPFROM2SHORT( MAXDIRSTRINGLENGTH-1, 0 ), 0 );
  2679.     WinSetDlgItemText( hWnd, DIRECTORY, menuItem->Directory);
  2680.     // set appropriate radio button for program startup option
  2681.     WinCheckButton( hWnd, MAXIMIZED, FALSE );
  2682.     WinCheckButton( hWnd, MINIMIZED, FALSE );
  2683.     SHORT ProgType = menuItem->ProgType;
  2684.     if (ProgType & STARTMAX)
  2685.         WinCheckButton( hWnd, MAXIMIZED, TRUE );
  2686.     else if (ProgType & STARTMIN)
  2687.         WinCheckButton( hWnd, MINIMIZED, TRUE );
  2688.     // set appropriate radio button for program startup option
  2689.     if (ProgType & PM)
  2690.         WinCheckButton( hWnd, PMAPP, TRUE );
  2691.     else if (ProgType & WPSFOLDER)
  2692.         WinCheckButton( hWnd, FOLDER, TRUE );
  2693.     else if ( (ProgType & DOS) && (ProgType & WINDOWED))
  2694.         WinCheckButton( hWnd, DOSWIN, TRUE );
  2695.     else if ( (ProgType & DOS) && (ProgType & FULLSCREEN))
  2696.         WinCheckButton( hWnd, DOSFS, TRUE );
  2697.     else if ( (ProgType & OS2) && (ProgType & WINDOWED))
  2698.         WinCheckButton( hWnd, OS2WIN, TRUE );
  2699.     else if ( (ProgType & OS2) && (ProgType & FULLSCREEN))
  2700.         WinCheckButton( hWnd, OS2FS, TRUE );
  2701.     else if ( (ProgType & WINOS2) && (ProgType & WINDOWED))
  2702.         WinCheckButton( hWnd, WINOS2WIN, TRUE );
  2703.     else if ( (ProgType & WINOS2) && (ProgType & FULLSCREEN))
  2704.         WinCheckButton( hWnd, WINOS2FS, TRUE );
  2705.     if (ProgType & STARTASWPS)
  2706.         WinCheckButton( hWnd, STARTWPS, TRUE );
  2707.     else
  2708.         WinCheckButton( hWnd, STARTWPS, FALSE );
  2709.     updateEditItemWindow( hWnd );
  2710. }
  2711.  
  2712.  
  2713. ////////////////////////////////////////////////////////////////////////////////
  2714. // message handler for the dialog "edit an item's values"
  2715. ////////////////////////////////////////////////////////////////////////////////
  2716. MRESULT EXPENTRY EditItemDataProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2717. {
  2718.     switch( msg )
  2719.     {
  2720.         //----------------------------------------------------------------------
  2721.         // if the object being drug over us is a single object, allow drag
  2722.         //----------------------------------------------------------------------
  2723.         case DM_DRAGOVER: {
  2724.             ULONG cbBuffer;
  2725.             DRAGITEM dragItem;
  2726.             PDRAGINFO dragInfoPtr;
  2727.             INT numObjects;
  2728.  
  2729.             dragInfoPtr = (PDRAGINFO)mp1;
  2730.             DrgAccessDraginfo(dragInfoPtr);
  2731.             numObjects = dragInfoPtr->cditem;
  2732.             cbBuffer = sizeof(DRAGITEM);
  2733.             DrgQueryDragitem( dragInfoPtr, cbBuffer, &dragItem, 0 );
  2734.             DrgFreeDraginfo(dragInfoPtr);
  2735.  
  2736.             // allow anything, if sent by itself, to be dropped on us
  2737.             if (numObjects == 1)
  2738.                 return MPFROM2SHORT( DOR_DROP, DO_UNKNOWN );
  2739.             return MPFROM2SHORT( DOR_NEVERDROP, DO_UNKNOWN );
  2740.             }
  2741.         //----------------------------------------------------------------------
  2742.         // allow the dropping of a WPS object to our window.  Once dropped, get
  2743.         // necessary info and fill in dialog with the info we retrieve
  2744.         //----------------------------------------------------------------------
  2745.         case DM_DROP: {
  2746.             PDRAGINFO dragInfoPtr;
  2747.             ULONG cbBuffer;
  2748.             DRAGITEM dragItem;
  2749.  
  2750.             dragInfoPtr = (PDRAGINFO)mp1;
  2751.             DrgAccessDraginfo(dragInfoPtr);
  2752.  
  2753.             cbBuffer = sizeof(DRAGITEM);
  2754.             DrgQueryDragitem( dragInfoPtr, cbBuffer, &dragItem, 0 );
  2755.  
  2756. /*
  2757.             {
  2758.             WPProgram* somSelf;
  2759.             PROGDETAILS Details;
  2760.             ULONG size = sizeof(Details);
  2761.  
  2762.             somSelf = (WPProgram*)OBJECT_FROM_PREC( dragItem.ulItemID );
  2763.  
  2764.             {
  2765.             char temp[128];
  2766.  
  2767.             sprintf(temp,"SomSelf drag ulItemID = %ld\nWPProgram* = %ld", dragItem.ulItemID, somSelf);
  2768.             WinMessageBox( HWND_DESKTOP, hwndFrame, temp, temp, 0,
  2769.                            MB_MOVEABLE|MB_OK);
  2770.             }
  2771.  
  2772.             //somTP_WPProgram_wpQueryProgDetails(somSelf,&Details,&size);
  2773.             WPProgram_wpQueryProgDetails(somSelf,&Details,&size);
  2774.             }
  2775. */
  2776.  
  2777.             USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2778.             // get menu item name
  2779.             DrgQueryStrName( dragItem.hstrTargetName, MAXITEMNAMELENGTH, menuItem->ItemName);
  2780.             // get default directory
  2781.             DrgQueryStrName( dragItem.hstrContainerName, MAXDIRSTRINGLENGTH, menuItem->Directory);
  2782.             // get path name
  2783.             DrgQueryStrName( dragItem.hstrSourceName, MAXACTIONSTRINGLENGTH, menuItem->ActionToDo);
  2784.  
  2785.             menuItem->ProgType = WPSFOLDER;
  2786.             WinCheckButton( hWnd, FOLDER, TRUE );
  2787.  
  2788.             DrgFreeDraginfo(dragInfoPtr);
  2789.             updateEditItemData( hWnd );
  2790.             WinSetFocus( HWND_DESKTOP, hWnd );
  2791.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2792.             }
  2793.         //----------------------------------------------------------------------
  2794.         // when the dialog is being initialized, center it on desktop and put
  2795.         // the current data into control fields
  2796.         //----------------------------------------------------------------------
  2797.         case WM_INITDLG: {
  2798.             SWP swp;
  2799.  
  2800.             // center dialog on screen
  2801.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  2802.             WinSetWindowPos( hWnd, (HWND)0,
  2803.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  2804.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  2805.                              0, 0, SWP_MOVE);
  2806.  
  2807.             // save data in case of cancel or restore
  2808.             USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2809.             oldProgType = menuItem->ProgType;
  2810.             strcpy( oldPassword, menuItem->Password );
  2811.             oldPasswordEnabled = menuItem->PasswordEnabled;
  2812.             strcpy( oldItemName, menuItem->ItemName );
  2813.             strcpy( oldDirectory, menuItem->Directory );
  2814.             strcpy( oldAction, menuItem->ActionToDo );
  2815.             strcpy( oldCmdLn, menuItem->CmdLnArgs );
  2816.             updateEditItemData( hWnd );
  2817.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2818.             }
  2819.         //----------------------------------------------------------------------
  2820.         // we received a control message, update enabling of buttons
  2821.         //----------------------------------------------------------------------
  2822.         case WM_CONTROL:
  2823.         {
  2824.             // make sure either maximize -or- minimize is checked, never both
  2825.             if ((SHORT1FROMMP(mp1)==MAXIMIZED) && (SHORT2FROMMP(mp1)==BN_CLICKED))
  2826.                 WinCheckButton( hWnd, MINIMIZED, FALSE );
  2827.             if ((SHORT1FROMMP(mp1)==MINIMIZED) && (SHORT2FROMMP(mp1)==BN_CLICKED))
  2828.                 WinCheckButton( hWnd, MAXIMIZED, FALSE );
  2829.             updateEditItemWindow( hWnd );
  2830.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  2831.         }
  2832.         //----------------------------------------------------------------------
  2833.         // process a command message received from the system
  2834.         //----------------------------------------------------------------------
  2835.         case WM_COMMAND:
  2836.         {
  2837.             USHORT command = SHORT1FROMMP(mp1);
  2838.             switch( command )
  2839.                 {
  2840.                 //--------------------------------------------------------------
  2841.                 //--------------------------------------------------------------
  2842.                 case PASSWORDENTRY: {
  2843.                     changePassword( Menus[MenuSelection][ItemSelection]->Password );
  2844.                     return 0;
  2845.                     }
  2846.                 //--------------------------------------------------------------
  2847.                 // open the settings notebook and allow user modifications
  2848.                 //--------------------------------------------------------------
  2849.                 case SETTINGSBUTTON: {
  2850.                     HOBJECT object;
  2851.  
  2852.                     // open settings for current program in dialog controls
  2853.                     USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2854.                     WinQueryDlgItemText( hWnd, ITEMNAME, MAXITEMNAMELENGTH,
  2855.                                          menuItem->ItemName);
  2856.                     WinQueryDlgItemText( hWnd, PATHNAME, MAXACTIONSTRINGLENGTH,
  2857.                                          menuItem->ActionToDo);
  2858.                     WinQueryDlgItemText( hWnd, ARGUMENTS, MAXARGSTRINGLENGTH,
  2859.                                          menuItem->CmdLnArgs);
  2860.                     WinQueryDlgItemText( hWnd, DIRECTORY, MAXDIRSTRINGLENGTH,
  2861.                                          menuItem->Directory);
  2862.  
  2863.                     if (menuItem->ProgType & WPSFOLDER)
  2864.                         sprintf(tmpBuffer, "%s%s\0", menuItem->Directory,
  2865.                                 menuItem->ActionToDo);
  2866.                     else
  2867.                         sprintf(tmpBuffer, "%s\0", menuItem->ActionToDo);
  2868.  
  2869.                     object = WinQueryObject( tmpBuffer );
  2870.                     if (object==NULLHANDLE) {
  2871.                         if (FileBarIsShell)
  2872.                             WinMessageBox( HWND_DESKTOP, hwndFrame, MSG29, MSG30, 0,
  2873.                                            MB_MOVEABLE|MB_OK|MB_ERROR);
  2874.                         else WinMessageBox( HWND_DESKTOP, hwndFrame, MSG31, MSG30, 0,
  2875.                                             MB_MOVEABLE|MB_OK|MB_ERROR);
  2876.                         return 0;
  2877.                         }
  2878.  
  2879.                     WinSetObjectData( object, "OPEN=SETTINGS" );
  2880.                     return 0;
  2881.                     }
  2882.                 //--------------------------------------------------------------
  2883.                 // the user wants to find a file to call as a menu item.  Hook
  2884.                 // into OS/2's file dialog procedure to ease the finding process
  2885.                 // for us to program!  Then once a file is selected, fill in
  2886.                 // the program path, directory and query the application for its
  2887.                 // application type and mark the appropriate radio button
  2888.                 //--------------------------------------------------------------
  2889.                 case FINDFILE: {
  2890.                     CHAR title[] = MSG32;
  2891.                     ULONG s, t;
  2892.                     HWND hwndDialog;
  2893.  
  2894.                     fileDlgInfo.fl = FDS_OPEN_DIALOG|FDS_CENTER;
  2895.                     fileDlgInfo.pszTitle = title;
  2896.                     strcat(fileDlgInfo.szFullFile, "*.*\0");
  2897.  
  2898.                     USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2899.                     hwndDialog = WinFileDlg( HWND_DESKTOP, hWnd, &fileDlgInfo );
  2900.                     if (hwndDialog && (fileDlgInfo.lReturn == DID_OK)) {
  2901.  
  2902.                         strcpy( menuItem->ActionToDo, fileDlgInfo.szFullFile );
  2903.  
  2904.                         s=strlen(fileDlgInfo.szFullFile);
  2905.                         while((fileDlgInfo.szFullFile[s]!='\\') && (s>=0))
  2906.                             s--;
  2907.  
  2908.                         t = 0;
  2909.                         while (t<s)
  2910.                             menuItem->Directory[t] = fileDlgInfo.szFullFile[t++];
  2911.                         menuItem->Directory[t] = '\0';
  2912.  
  2913.                         DosQueryAppType( menuItem->ActionToDo, &t);
  2914.                         menuItem->ProgType = OS2 + WINDOWED;
  2915.                         if (t == FAPPTYP_WINDOWAPI)
  2916.                             menuItem->ProgType = PM;
  2917.                         if (t == FAPPTYP_WINDOWCOMPAT)
  2918.                             menuItem->ProgType = OS2 + WINDOWED;
  2919.                         if (t == FAPPTYP_NOTWINDOWCOMPAT)
  2920.                             menuItem->ProgType = OS2 + FULLSCREEN;
  2921.                         if (t == FAPPTYP_DOS)
  2922.                             menuItem->ProgType = DOS + WINDOWED;
  2923.                         if ((t == FAPPTYP_WINDOWSREAL) || (t == FAPPTYP_WINDOWSPROT))
  2924.                             menuItem->ProgType = WINOS2 + FULLSCREEN;
  2925.  
  2926.                         updateEditItemData( hWnd );
  2927.                         updateEditItemWindow( hWnd );
  2928.  
  2929.                         if (fileDlgInfo.szFullFile[s]=='\\')
  2930.                             fileDlgInfo.szFullFile[s+1]='\0';
  2931.                         else
  2932.                             fileDlgInfo.szFullFile[0]='\0';
  2933.                         }
  2934.                     else
  2935.                         fileDlgInfo.szFullFile[0]='\0';
  2936.                     return 0;
  2937.                     }
  2938.                 //--------------------------------------------------------------
  2939.                 // user pressed Reset, restore old settings and continue
  2940.                 //--------------------------------------------------------------
  2941.                 case RESETBUTTON: {
  2942.                     USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2943.                     menuItem->PasswordEnabled = oldPasswordEnabled;
  2944.                     menuItem->ProgType = oldProgType;
  2945.                     strcpy( menuItem->Password, oldPassword );
  2946.                     strcpy( menuItem->ItemName, oldItemName );
  2947.                     strcpy( menuItem->Directory, oldDirectory );
  2948.                     strcpy( menuItem->ActionToDo, oldAction );
  2949.                     strcpy( menuItem->CmdLnArgs, oldCmdLn );
  2950.                     updateEditItemData( hWnd );
  2951.                     return 0;
  2952.                     }
  2953.                 //--------------------------------------------------------------
  2954.                 // user pressed CANCEL, restore old item data
  2955.                 //--------------------------------------------------------------
  2956.                 case DID_CANCEL: {
  2957.                     USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2958.                     menuItem->PasswordEnabled = oldPasswordEnabled;
  2959.                     menuItem->ProgType = oldProgType;
  2960.                     strcpy( menuItem->Password, oldPassword );
  2961.                     strcpy( menuItem->ItemName, oldItemName );
  2962.                     strcpy( menuItem->Directory, oldDirectory );
  2963.                     strcpy( menuItem->ActionToDo, oldAction );
  2964.                     strcpy( menuItem->CmdLnArgs, oldCmdLn );
  2965.                     WinDismissDlg( hWnd, TRUE );
  2966.                     return 0;
  2967.                     }
  2968.                 //--------------------------------------------------------------
  2969.                 // user pressed OK, save current information for this item
  2970.                 //--------------------------------------------------------------
  2971.                 case DID_OK: {
  2972.                     // save program type and max/min startup status
  2973.                     USERMENUITEM* menuItem = Menus[MenuSelection][ItemSelection];
  2974.  
  2975.                     if (WinQueryButtonCheckstate( hWnd, PASSWORDPROTECT ))
  2976.                         menuItem->PasswordEnabled = YES;
  2977.                     else menuItem->PasswordEnabled = NO;
  2978.  
  2979.                     menuItem->ProgType = 0;
  2980.                     if (WinQueryButtonCheckstate( hWnd, FOLDER ))
  2981.                         menuItem->ProgType = WPSFOLDER;
  2982.                     if (WinQueryButtonCheckstate( hWnd, OS2WIN ))
  2983.                         menuItem->ProgType = OS2 + WINDOWED;
  2984.                     if (WinQueryButtonCheckstate( hWnd, OS2FS ))
  2985.                         menuItem->ProgType = OS2 + FULLSCREEN;
  2986.                     if (WinQueryButtonCheckstate( hWnd, DOSWIN ))
  2987.                         menuItem->ProgType = DOS + WINDOWED;
  2988.                     if (WinQueryButtonCheckstate( hWnd, DOSFS ))
  2989.                         menuItem->ProgType = DOS + FULLSCREEN;
  2990.                     if (WinQueryButtonCheckstate( hWnd, WINOS2WIN ))
  2991.                         menuItem->ProgType = WINOS2 + WINDOWED;
  2992.                     if (WinQueryButtonCheckstate( hWnd, WINOS2FS ))
  2993.                         menuItem->ProgType = WINOS2 + FULLSCREEN;
  2994.                     if (WinQueryButtonCheckstate( hWnd, PMAPP ))
  2995.                         menuItem->ProgType = PM;
  2996.                     if (WinQueryButtonCheckstate( hWnd, MAXIMIZED ))
  2997.                         menuItem->ProgType = menuItem->ProgType | STARTMAX;
  2998.                     if (WinQueryButtonCheckstate( hWnd, MINIMIZED ))
  2999.                         menuItem->ProgType = menuItem->ProgType | STARTMIN;
  3000.                     if (WinQueryButtonCheckstate( hWnd, STARTWPS ))
  3001.                         menuItem->ProgType = menuItem->ProgType | STARTASWPS;
  3002.  
  3003.                     // save name, path, directory, command line args
  3004.                     WinQueryDlgItemText( hWnd, ITEMNAME, MAXITEMNAMELENGTH,
  3005.                                          menuItem->ItemName);
  3006.                     WinQueryDlgItemText( hWnd, PATHNAME, MAXACTIONSTRINGLENGTH,
  3007.                                          menuItem->ActionToDo);
  3008.                     WinQueryDlgItemText( hWnd, ARGUMENTS, MAXARGSTRINGLENGTH,
  3009.                                          menuItem->CmdLnArgs);
  3010.                     WinQueryDlgItemText( hWnd, DIRECTORY, MAXDIRSTRINGLENGTH,
  3011.                                          menuItem->Directory);
  3012.                     WinDismissDlg( hWnd, TRUE );
  3013.                     return 0;
  3014.                     }
  3015.             default:
  3016.                 return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3017.             }
  3018.         }
  3019.         //----------------------------------------------------------------------
  3020.         // if nothing further we want to intercept, pass message onto system
  3021.         //----------------------------------------------------------------------
  3022.         default:
  3023.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3024.     }
  3025. }
  3026.  
  3027.  
  3028. ////////////////////////////////////////////////////////////////////////////////
  3029. // Message handler for entering a runtime parameter
  3030. ////////////////////////////////////////////////////////////////////////////////
  3031. MRESULT EXPENTRY EnterParamProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  3032. {
  3033.    switch( msg )
  3034.     {
  3035.         //----------------------------------------------------------------------
  3036.         // when the dialog is being initialized, center it on desktop
  3037.         //----------------------------------------------------------------------
  3038.         case WM_INITDLG: {
  3039.             SWP swp;
  3040.  
  3041.             WinSetWindowText( hWnd, parameterTitle );
  3042.             WinSetDlgItemText( hWnd, PARAMETER_TEXT, ParameterTextPtr );
  3043.             WinSendDlgItemMsg( hWnd, PARAMETER_EDIT, EM_SETTEXTLIMIT, MPFROMSHORT( oldProgType ), 0 );
  3044.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  3045.             WinSetWindowPos( hWnd, (HWND)0,
  3046.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  3047.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  3048.                              0, 0, SWP_MOVE);
  3049.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3050.             }
  3051.         //----------------------------------------------------------------------
  3052.         // if we receive any system message, dismiss the dialog box
  3053.         //----------------------------------------------------------------------
  3054.         case WM_COMMAND:
  3055.         {
  3056.             memset(variableText, 0, sizeof(variableText) );
  3057.             WinQueryDlgItemText( hWnd, PARAMETER_EDIT, oldProgType, (PSZ)variableText );
  3058.             WinDismissDlg( hWnd, TRUE );
  3059.             return 0;
  3060.         }
  3061.         //----------------------------------------------------------------------
  3062.         // if nothing further we want to intercept, pass message onto system
  3063.         //----------------------------------------------------------------------
  3064.         default:
  3065.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3066.     }
  3067. }
  3068.  
  3069.  
  3070. ////////////////////////////////////////////////////////////////////////////////
  3071. // gives a newly start application the input focus
  3072. ////////////////////////////////////////////////////////////////////////////////
  3073. void giveApplicationFocus( BOOLEAN maximize, BOOLEAN minimize )
  3074. {
  3075.     SHORT i,h;
  3076.     PSWBLOCK SwitchBlockPtr;
  3077.     ULONG numItems = WinQuerySwitchList( hab, NULL, 0 );
  3078.     ULONG Buffer;
  3079.     SHORT count = 0;
  3080.  
  3081.     while ((numItems == oldNumItems) && (++count < MAXCOUNT)) {
  3082.         DosSleep(20);
  3083.         numItems = WinQuerySwitchList( hab, NULL, 0 );
  3084.         }
  3085.  
  3086.     Buffer = (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
  3087.     PVOID my = new BYTE[Buffer];
  3088.     WinQuerySwitchList( hab, (SWBLOCK*)my, Buffer );
  3089.     SwitchBlockPtr = (PSWBLOCK)(my);
  3090.  
  3091.     for (i=0; i<numItems; i++)
  3092.         for (h=0; h<oldNumItems; h++)
  3093.            if ( SwitchBlockPtr->aswentry[i].swctl.hwnd == oldTaskHandles[h])
  3094.                 SwitchBlockPtr->aswentry[i].swctl.hwnd = NULLHANDLE;
  3095.  
  3096.     i = 0;
  3097.     while (SwitchBlockPtr->aswentry[i].swctl.hwnd == NULLHANDLE)
  3098.         i++;
  3099.     WinFocusChange( HWND_DESKTOP, hwndFrame, 0 );
  3100.     WinSwitchToProgram( SwitchBlockPtr->aswentry[i].hswitch );
  3101.  
  3102.     if (maximize)
  3103.         WinSetWindowPos( SwitchBlockPtr->aswentry[i].swctl.hwnd, (HWND)0, 0, 0,
  3104.                          0, 0, SWP_MAXIMIZE);
  3105.     else if (minimize)
  3106.         WinSetWindowPos( SwitchBlockPtr->aswentry[i].swctl.hwnd, (HWND)0, 0, 0,
  3107.                          0, 0, SWP_MINIMIZE);
  3108. }
  3109.  
  3110.  
  3111. ////////////////////////////////////////////////////////////////////////////////
  3112. // startApplication uses DosStartSession to start a batch file to start an
  3113. // application pointed to in one of the user menus by menu and item variables.
  3114. ////////////////////////////////////////////////////////////////////////////////
  3115. SHORT startApplication( SHORT menu, SHORT item )
  3116. {
  3117.     ULONG currentDrive;
  3118.     UCHAR defaultDirectory[MAXPATH];
  3119.     CHAR* settingsFile;
  3120.     APIRET rc;
  3121.     STARTDATA startData;
  3122.     ULONG sessionId;
  3123.     PID ppId;
  3124.     UCHAR ObjBuf[2];
  3125.     SHORT i;
  3126.     SHORT h;
  3127.     PSWBLOCK SwitchBlockPtr;
  3128.     ULONG oldBuffer;
  3129.     CHAR parameters[MAXARGSTRINGLENGTH*3];
  3130.     CHAR SettingsBuffer[WPSBUFFER];
  3131.     CHAR itemName[MAXITEMNAMELENGTH];
  3132.     USERMENUITEM* menuItem = Menus[menu][item];
  3133.  
  3134. /////////////////////////////////////////////////////////////////////////////////
  3135.     oldNumItems = WinQuerySwitchList( hab, NULL, 0 );
  3136.     oldBuffer = (oldNumItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
  3137.     PVOID myBuffer = new BYTE[oldBuffer];
  3138.     WinQuerySwitchList( hab, (SWBLOCK*)myBuffer, oldBuffer );
  3139.     SwitchBlockPtr = (PSWBLOCK)(myBuffer);
  3140.     for (i=0; i < oldNumItems; i++)
  3141.         oldTaskHandles[i] = SwitchBlockPtr->aswentry[i].swctl.hwnd;
  3142.     delete(myBuffer);
  3143. /////////////////////////////////////////////////////////////////////////////////
  3144.  
  3145.     // remove tilde from title window
  3146.     i = 0;
  3147.     h = 0;
  3148.     while (menuItem->ItemName[i]!='\0') {
  3149.         if (menuItem->ItemName[i]!='~')
  3150.             itemName[h++] = menuItem->ItemName[i];
  3151.         i++;
  3152.         }
  3153.     itemName[h] = 0;
  3154.  
  3155.     // get command line arguments via user input if necessary
  3156.     i = 0;
  3157.     h = 0;
  3158.     while ( menuItem->CmdLnArgs[i] != 0 ) {
  3159.         if (menuItem->CmdLnArgs[i] == STARTINPUT) {
  3160.             short j = 0;
  3161.             CHAR tmp[MAXARGSTRINGLENGTH];
  3162.  
  3163.             i++;
  3164.             while ( (menuItem->CmdLnArgs[i] != 0) &&
  3165.                     (menuItem->CmdLnArgs[i] != ENDINPUT ))
  3166.                 tmp[j++] = menuItem->CmdLnArgs[i++];
  3167.             tmp[j] = 0;
  3168.  
  3169.             if (menuItem->CmdLnArgs[i] != 0)
  3170.                 i++;
  3171.  
  3172.             {
  3173.                 CHAR mesg[18+MAXARGSTRINGLENGTH];
  3174.                 SHORT k = 0;
  3175.  
  3176.                 sprintf( parameterTitle, "%s %s", menuItem->ItemName, MSG33 );
  3177.                 sprintf( mesg, "%s '%s'", MSG34, tmp);
  3178.                 ParameterTextPtr = mesg;
  3179.                 oldProgType = sizeof(variableText);
  3180.                 (VOID*)WinDlgBox(HWND_DESKTOP,
  3181.                                  hwndFrame,
  3182.                                  (PFNWP)EnterParamProc,
  3183.                                  0,
  3184.                                  ENTERPARAMETER,
  3185.                                  (PVOID)NULL);
  3186.  
  3187.                 while ( variableText[k] != '\0')
  3188.                     parameters[h++] = variableText[k++];
  3189.             }
  3190.  
  3191.             }
  3192.         else
  3193.             parameters[h++] = menuItem->CmdLnArgs[i++];
  3194.         }
  3195.     parameters[h] = '\0';
  3196.  
  3197.     //--------------------------------------------------------------------------
  3198.     // open a WPS folder/object
  3199.     //--------------------------------------------------------------------------
  3200.     if ((menuItem->ProgType & WPSFOLDER) ||
  3201.     (menuItem->ProgType & STARTASWPS)) {
  3202.     HOBJECT object;
  3203.     CHAR string[MAXACTIONSTRINGLENGTH +
  3204.             MAXDIRSTRINGLENGTH+2];
  3205.  
  3206.     if (menuItem->ProgType & WPSFOLDER)
  3207.         sprintf(string, "%s%s\0", menuItem->Directory,
  3208.             menuItem->ActionToDo);
  3209.     else
  3210.         sprintf(string, "%s\0", menuItem->ActionToDo);
  3211.  
  3212.     object = WinQueryObject( string );
  3213.     if (object==NULLHANDLE) {
  3214.         CHAR pcDir[MAXPATH];
  3215.         strcpy( pcDir, menuItem->Directory );
  3216.         pcDir[strlen( pcDir ) - 1] = 0;
  3217.         object = WinCreateObject( "WPProgram",
  3218.                 menuItem->ActionToDo, "OPEN=DEFAULT",
  3219.                 pcDir, CO_UPDATEIFEXISTS );
  3220.         }
  3221.  
  3222.             if (object) {
  3223.                 // launch the item
  3224.                 WinSetObjectData(object, "OPEN=DEFAULT");
  3225.                 // give it focus by attempting to launch it again
  3226.                 WinSetObjectData(object, "OPEN=DEFAULT");
  3227.                 }
  3228.             return 0;
  3229.     }
  3230.  
  3231.     //--------------------------------------------------------------------------
  3232.     // try and locate a settings file
  3233.     //--------------------------------------------------------------------------
  3234.     {
  3235.     SHORT offset = 0;
  3236.     FILE *FileHandle;
  3237.     CHAR temp[MAXPATH+5];
  3238.     ULONG tempSize = MAXPATH;
  3239.     ULONG driveMap;
  3240.  
  3241.     // save current working drive and path
  3242.     DosQueryCurrentDisk( ¤tDrive, &driveMap );
  3243.     defaultDirectory[0]= (currentDrive+'A'-1);
  3244.     defaultDirectory[1]= ':';
  3245.     defaultDirectory[2]= '\\';
  3246.     defaultDirectory[3]= '\0';
  3247.     DosQueryCurrentDir( currentDrive, (CHAR*)&temp, &tempSize );
  3248.     strcat( defaultDirectory, temp );
  3249.  
  3250.     // point to working directory of program to execute
  3251.     if (((toupper(menuItem->Directory[0]))>='A') && ((toupper(menuItem->Directory[0]))<='Z'))
  3252.         DosSetDefaultDisk( (ULONG)(toupper(menuItem->Directory[0])-'A' + 1) );
  3253.     DosSetCurrentDir( menuItem->Directory );
  3254.  
  3255.     settingsFile = 0;
  3256.     memset( &SettingsBuffer[0], 0, sizeof(SettingsBuffer) );
  3257.     if ((FileHandle = fopen("SETTINGS.INI","rt")) != NULL) {
  3258.         CHAR ch;
  3259.  
  3260.         while (fscanf(FileHandle, "%c", &ch) != EOF) {
  3261.             if ( ch == '\n' )
  3262.                 SettingsBuffer[ offset++ ] = '\0';
  3263.             else
  3264.                 if ( ch != '\r' )
  3265.                     SettingsBuffer[ offset++ ] = ch;
  3266.             }
  3267.         SettingsBuffer[ offset++ ] = '\0';
  3268.         SettingsBuffer[ offset++ ] = '\0';
  3269.         fclose(FileHandle);
  3270.         settingsFile = SettingsBuffer;
  3271.         }
  3272.  
  3273.     // restore current drive and directory
  3274.     DosSetDefaultDisk( currentDrive );
  3275.     DosSetCurrentDir( defaultDirectory );
  3276.     }
  3277.  
  3278.  
  3279.     //--------------------------------------------------------------------------
  3280.     // this launches a command shell (DOS or OS2 (Windowed or FS session))
  3281.     //--------------------------------------------------------------------------
  3282.     if ((menuItem->ActionToDo[0] == '\0') && !(menuItem->ProgType & WINOS2)) {
  3283.         CHAR InputDir[MAXPATH + 9];
  3284.  
  3285.         DosSetDefaultDisk( (ULONG)(toupper(menuItem->Directory[0])-'A' + 1) );
  3286.         DosSetCurrentDir( menuItem->Directory );
  3287.  
  3288.         memset( &startData, 0, sizeof(STARTDATA) );
  3289.         startData.Related = SSF_RELATED_INDEPENDENT;
  3290.         startData.FgBg = SSF_FGBG_FORE;
  3291.         startData.TraceOpt = SSF_TRACEOPT_NONE;
  3292.         startData.InheritOpt = SSF_INHERTOPT_PARENT;
  3293.         startData.ObjectBuffer = ObjBuf;
  3294.         startData.ObjectBuffLen = sizeof(ObjBuf);
  3295.         startData.Length = 32;
  3296.         startData.PgmTitle = itemName;
  3297.         strcpy( InputDir, "/K cd  \0");
  3298.         strcpy( InputDir+6, menuItem->Directory );
  3299.         startData.PgmInputs = InputDir;
  3300.         startData.Environment = settingsFile;
  3301.  
  3302.         startData.PgmControl = SSF_CONTROL_VISIBLE;
  3303.         if (menuItem->ProgType & MAXIMIZED)
  3304.             startData.PgmControl = SSF_CONTROL_VISIBLE | SSF_CONTROL_MAXIMIZE;
  3305.         else if (menuItem->ProgType & MINIMIZED)
  3306.             startData.PgmControl = SSF_CONTROL_VISIBLE | SSF_CONTROL_MINIMIZE;
  3307.  
  3308.         if (menuItem->ProgType & DOS) {
  3309.             if (menuItem->ProgType & WINDOWED)
  3310.                 startData.SessionType = SSF_TYPE_WINDOWEDVDM;
  3311.             else
  3312.                 startData.SessionType = SSF_TYPE_VDM;
  3313.             rc = DosStartSession( (STARTDATA*) &startData, (ULONG*)&sessionId,
  3314.                                   (PID*) &ppId );
  3315.  
  3316.             giveApplicationFocus( (menuItem->ProgType & MAXIMIZED),
  3317.                                   (menuItem->ProgType & MINIMIZED) );
  3318.             DosSetDefaultDisk( currentDrive );
  3319.             DosSetCurrentDir( defaultDirectory );
  3320.             return 0;
  3321.             }
  3322.         else if (menuItem->ProgType & OS2) {
  3323.             if (menuItem->ProgType & WINDOWED)
  3324.                 startData.SessionType = SSF_TYPE_WINDOWABLEVIO;
  3325.             else
  3326.                 startData.SessionType = SSF_TYPE_FULLSCREEN;
  3327.             rc = DosStartSession( (STARTDATA*) &startData, (ULONG*)&sessionId,
  3328.                                   (PID*) &ppId );
  3329.  
  3330.             giveApplicationFocus( (menuItem->ProgType & MAXIMIZED),
  3331.                                   (menuItem->ProgType & MINIMIZED) );
  3332.             DosSetDefaultDisk( currentDrive );
  3333.             DosSetCurrentDir( defaultDirectory );
  3334.             return 0;
  3335.             }
  3336.         WinMessageBox( HWND_DESKTOP, hwndFrame, MSG37, NULL, 0,
  3337.                        MB_MOVEABLE|MB_ERROR|MB_OK);
  3338.  
  3339.         return 0;
  3340.         }
  3341.  
  3342.     //--------------------------------------------------------------------------
  3343.     // this section of code launches a program (non-command shell application)
  3344.     //--------------------------------------------------------------------------
  3345.     {
  3346.     CHAR inputs[1024];
  3347.  
  3348.     memset( &startData, 0, sizeof(STARTDATA) );
  3349.     startData.Length = sizeof(STARTDATA);
  3350.     startData.Related = SSF_RELATED_INDEPENDENT;
  3351.     startData.FgBg = SSF_FGBG_FORE;
  3352.     startData.TraceOpt = SSF_TRACEOPT_NONE;
  3353.     startData.PgmTitle = itemName;
  3354.     startData.InheritOpt = SSF_INHERTOPT_PARENT;
  3355.     startData.SessionType = SSF_TYPE_WINDOWABLEVIO;
  3356.     startData.PgmControl = SSF_CONTROL_VISIBLE;
  3357.     startData.SessionType = SSF_TYPE_PM;
  3358.     startData.PgmName = menuItem->ActionToDo;
  3359.     startData.PgmInputs = parameters;
  3360.     startData.Environment = settingsFile;
  3361.  
  3362.     if (menuItem->ProgType & DOS) {
  3363.         if (menuItem->ProgType & FULLSCREEN)
  3364.             startData.SessionType = SSF_TYPE_VDM;
  3365.         else if (menuItem->ProgType & WINDOWED)
  3366.             startData.SessionType = SSF_TYPE_WINDOWEDVDM;
  3367.         }
  3368.     else if (menuItem->ProgType & OS2) {
  3369.         if (menuItem->ProgType & FULLSCREEN)
  3370.             startData.SessionType = SSF_TYPE_FULLSCREEN;
  3371.         else if (menuItem->ProgType & WINDOWED)
  3372.             startData.SessionType = SSF_TYPE_WINDOWABLEVIO;
  3373.         }
  3374.  
  3375.     else if (menuItem->ProgType & WINOS2) {
  3376.         if (menuItem->ProgType & FULLSCREEN)
  3377.             startData.SessionType = SSF_TYPE_FULLSCREEN;
  3378.         else if (menuItem->ProgType & WINDOWED)
  3379.            startData.SessionType = 18;               //PROG_31_ENHSEAMLESSCOMMON
  3380.         if (menuItem->ActionToDo[0])
  3381.             sprintf( inputs, "/c winos2 %s %s", menuItem->ActionToDo, parameters );
  3382.         else
  3383.             sprintf( inputs, "/c winos2 %s", parameters );
  3384.         startData.PgmInputs = inputs;
  3385.         startData.PgmName = 0;
  3386.         }
  3387.  
  3388.     if (menuItem->ProgType & STARTMAX)
  3389.         startData.PgmControl |= SSF_CONTROL_MAXIMIZE;
  3390.     else if (menuItem->ProgType & STARTMIN)
  3391.         startData.PgmControl |= SSF_CONTROL_MINIMIZE;
  3392.  
  3393.     if (!(menuItem->ProgType & WINOS2) && (startData.PgmName != NULL) && (startData.SessionType != SSF_TYPE_PM)) {
  3394.         CHAR temp[MAXPATH+MAXARGSTRINGLENGTH+6];
  3395.         sprintf(temp, "/c %s %s\0", menuItem->ActionToDo, parameters);
  3396.         startData.PgmName = 0;
  3397.         strcpy(inputs, temp);
  3398.         startData.PgmInputs = inputs;
  3399.         }
  3400.  
  3401.     // point to working directory of program to execute
  3402.     if (((toupper(menuItem->Directory[0]))>='A') && ((toupper(menuItem->Directory[0]))<='Z'))
  3403.         DosSetDefaultDisk( (ULONG)(toupper(menuItem->Directory[0])-'A' + 1) );
  3404.     DosSetCurrentDir( menuItem->Directory );
  3405.  
  3406.     // launch application
  3407.     rc = DosStartSession( (STARTDATA*) &startData, (ULONG*)&sessionId,
  3408.                           (PID*) &ppId );
  3409.  
  3410.     // restore current drive and directory
  3411.     DosSetDefaultDisk( currentDrive );
  3412.     DosSetCurrentDir( defaultDirectory );
  3413.  
  3414.     if ((rc != 0) && (rc != ERROR_SMG_START_IN_BACKGROUND) && (!startUp)) {
  3415.         char text[] = MSG38;
  3416.         char title[28];
  3417.  
  3418.         sprintf(title, "%s #%d", MSG39, rc );
  3419.         WinMessageBox( HWND_DESKTOP, hwndFrame, text, title, 0,
  3420.                        MB_MOVEABLE|MB_ERROR|MB_OK);
  3421.         return 0;
  3422.         }
  3423.  
  3424.     giveApplicationFocus( (menuItem->ProgType & MAXIMIZED),
  3425.                           (menuItem->ProgType & MINIMIZED) );
  3426.     return 0;
  3427.     }
  3428. }
  3429.  
  3430.  
  3431. ////////////////////////////////////////////////////////////////////////////////
  3432. // display a background bitmap
  3433. ////////////////////////////////////////////////////////////////////////////////
  3434. VOID displayBackground( VOID )
  3435. {
  3436.     DESKTOP desktop;
  3437.  
  3438. //    if ((!FileBarIsShell) && (showBackground))
  3439. //        WinMessageBox( HWND_DESKTOP, hwndFrame, "The background bitmap could not be displayed since FileBar is not currently acting as the shell.", "FileBar - Display Background", 0,
  3440. //                       MB_MOVEABLE|MB_ERROR|MB_OK);
  3441. //    else
  3442.     if ((showBackground) || (isBackgroundDisplayed)) {
  3443.         desktop.cbSize = sizeof( DESKTOP );
  3444.         desktop.hbm = 0;
  3445.         desktop.x = 0;
  3446.         desktop.y = 0;
  3447.         desktop.fl = SDT_DESTROY;
  3448.         if (isBackgroundDisplayed)
  3449.             WinSetDesktopBkgnd( HWND_DESKTOP, &desktop );
  3450.  
  3451.         desktop.fl = SDT_LOADFILE|SDT_CENTER;
  3452.         if (backgroundAttr & SCALED)
  3453.             desktop.fl = SDT_SCALE|SDT_LOADFILE;
  3454.         if (backgroundAttr & TILED) {
  3455.             desktop.fl = SDT_TILE|SDT_LOADFILE;
  3456.             desktop.lTileCount = backgroundAttr - TILED;
  3457.             }
  3458.         strcpy( desktop.szFile, backgroundBitmap );
  3459.         if (showBackground) {
  3460.             WinSetDesktopBkgnd( HWND_DESKTOP, &desktop );
  3461.             isBackgroundDisplayed = TRUE;
  3462.             }
  3463.         }
  3464. }
  3465.  
  3466.  
  3467. ////////////////////////////////////////////////////////////////////////////////
  3468. // Message handler for a generic information-only dialog box (help & prod info)
  3469. ////////////////////////////////////////////////////////////////////////////////
  3470. MRESULT EXPENTRY backgroundProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  3471. {
  3472.    switch( msg )
  3473.     {
  3474.         //----------------------------------------------------------------------
  3475.         // when the dialog is being initialized, center it on desktop
  3476.         //----------------------------------------------------------------------
  3477.         case WM_INITDLG: {
  3478.             SWP swp;
  3479.             char temp[12];
  3480.  
  3481.             WinCheckButton( hWnd, BKGND_NORMAL, TRUE );
  3482.             if (backgroundAttr & SCALED)
  3483.                 WinCheckButton( hWnd, BKGND_SCALED, TRUE );
  3484.             else if (backgroundAttr & TILED) {
  3485.                 WinCheckButton( hWnd, BKGND_TILED, TRUE );
  3486.                 WinEnableControl( hWnd, BKGND_TILENUMBER, TRUE );
  3487.                 WinEnableControl( hWnd, BKGND_TILENUMBERTEXT, TRUE );
  3488.                 WinEnableControl( hWnd, BKGND_LESS, TRUE );
  3489.                 WinEnableControl( hWnd, BKGND_MORE, TRUE );
  3490.                 }
  3491.  
  3492.             if (backgroundAttr & SCALED)
  3493.                 backgroundAttr = backgroundAttr - SCALED;
  3494.             if (backgroundAttr & TILED)
  3495.                 backgroundAttr = backgroundAttr - TILED;
  3496.  
  3497.             sprintf(temp,"%d x %d", backgroundAttr, backgroundAttr);
  3498.             WinSetDlgItemText( hWnd, BKGND_TILENUMBER, temp );
  3499.  
  3500.             WinSendDlgItemMsg( hWnd, BKGND_BITMAPNAME, EM_SETTEXTLIMIT, MPFROMSHORT( sizeof(backgroundBitmap) ), 0 );
  3501.             WinSetDlgItemText( hWnd, BKGND_BITMAPNAME, backgroundBitmap );
  3502.  
  3503.             WinCheckButton( hWnd, BKGND_SHOW, showBackground );
  3504.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  3505.             WinSetWindowPos( hWnd, (HWND)0,
  3506.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  3507.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  3508.                              0, 0, SWP_MOVE);
  3509.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3510.             }
  3511.         //----------------------------------------------------------------------
  3512.         //----------------------------------------------------------------------
  3513.         case WM_CONTROL:
  3514.         {
  3515.             if (SHORT2FROMMP(mp1)==BN_CLICKED) {
  3516.                 BOOLEAN option = FALSE;
  3517.                 if (WinQueryButtonCheckstate( hWnd, BKGND_TILED))
  3518.                     option = TRUE;
  3519.                 WinEnableControl( hWnd, BKGND_TILENUMBER, option );
  3520.                 WinEnableControl( hWnd, BKGND_TILENUMBERTEXT, option );
  3521.                 WinEnableControl( hWnd, BKGND_LESS, option );
  3522.                 WinEnableControl( hWnd, BKGND_MORE, option );
  3523.                 }
  3524.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3525.         }
  3526.         //----------------------------------------------------------------------
  3527.         //----------------------------------------------------------------------
  3528.         case WM_COMMAND:
  3529.         {
  3530.             USHORT command = SHORT1FROMMP(mp1);
  3531.             switch( command )
  3532.                 {
  3533.                 //--------------------------------------------------------------
  3534.                 // if they pressed OK, then save the data in the dialog as an
  3535.                 // item that we can now launch from the fileBar.
  3536.                 //--------------------------------------------------------------
  3537.                 case DID_OK: {
  3538.                     WinQueryDlgItemText( hWnd, BKGND_BITMAPNAME, sizeof(backgroundBitmap), (PSZ)backgroundBitmap );
  3539.                     showBackground = WinQueryButtonCheckstate( hWnd, BKGND_SHOW );
  3540.                     if (WinQueryButtonCheckstate( hWnd, BKGND_SCALED))
  3541.                         backgroundAttr = backgroundAttr + SCALED;
  3542.                     if (WinQueryButtonCheckstate( hWnd, BKGND_TILED))
  3543.                         backgroundAttr = backgroundAttr + TILED;
  3544.                     WinDismissDlg( hWnd, TRUE );
  3545.                     return 0;
  3546.                     }
  3547.                 //--------------------------------------------------------------
  3548.                 //--------------------------------------------------------------
  3549.                 case BKGND_LESS: {
  3550.                     char temp[12];
  3551.  
  3552.                     if (backgroundAttr > 1)
  3553.                         backgroundAttr--;
  3554.                     sprintf(temp,"%d x %d", backgroundAttr, backgroundAttr);
  3555.                     WinSetDlgItemText( hWnd, BKGND_TILENUMBER, temp );
  3556.                     return 0;
  3557.                     }
  3558.                 //--------------------------------------------------------------
  3559.                 //--------------------------------------------------------------
  3560.                 case BKGND_MORE: {
  3561.                     char temp[12];
  3562.  
  3563.                     if (backgroundAttr < 32)
  3564.                         backgroundAttr++;
  3565.                     sprintf(temp,"%d x %d", backgroundAttr, backgroundAttr);
  3566.                     WinSetDlgItemText( hWnd, BKGND_TILENUMBER, temp );
  3567.                     return 0;
  3568.                     }
  3569.                 //--------------------------------------------------------------
  3570.                 //--------------------------------------------------------------
  3571.                 case BKGND_FINDFILE: {
  3572.                     CHAR title[] = MSG40;
  3573.                     HWND hwndDialog;
  3574.                     CHAR oldDir[MAXPATH];
  3575.  
  3576.                     fileDlgInfo.fl = FDS_OPEN_DIALOG|FDS_CENTER;
  3577.                     fileDlgInfo.pszTitle = title;
  3578.                     strcpy( oldDir, fileDlgInfo.szFullFile );
  3579.                     strcat(fileDlgInfo.szFullFile, "*.BMP\0");
  3580.  
  3581.                     hwndDialog = WinFileDlg( HWND_DESKTOP, hWnd, &fileDlgInfo );
  3582.                     if (hwndDialog && (fileDlgInfo.lReturn == DID_OK)) {
  3583.                         strcpy( backgroundBitmap, fileDlgInfo.szFullFile );
  3584.                         resetFileDialog();
  3585.                         WinSetDlgItemText( hWnd, BKGND_BITMAPNAME, backgroundBitmap );
  3586.                         }
  3587.                     else
  3588.                         strcpy( fileDlgInfo.szFullFile, oldDir );
  3589.                     return 0;
  3590.                     }
  3591.             }
  3592.         }
  3593.         //----------------------------------------------------------------------
  3594.         // if nothing further we want to intercept, pass message onto system
  3595.         //----------------------------------------------------------------------
  3596.         default:
  3597.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3598.     }
  3599. }
  3600.  
  3601.  
  3602. ////////////////////////////////////////////////////////////////////////////////
  3603. // Message handler for a generic information-only dialog box (help & prod info)
  3604. ////////////////////////////////////////////////////////////////////////////////
  3605. MRESULT EXPENTRY startupProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  3606. {
  3607.    switch( msg )
  3608.     {
  3609.         //----------------------------------------------------------------------
  3610.         // when the dialog is being initialized, center it on desktop
  3611.         //----------------------------------------------------------------------
  3612.         case WM_INITDLG: {
  3613.             SWP swp;
  3614.             short i,j;
  3615.             char temp[MAXITEMNAMELENGTH+8];
  3616.  
  3617.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  3618.             WinSetWindowPos( hWnd, (HWND)0,
  3619.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  3620.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  3621.                              0, 0, SWP_MOVE);
  3622.             WinSendDlgItemMsg( hWnd, STARTUP_ITEMLIST, LM_DELETEALL, 0, 0);
  3623.             temp[0] = ' ';
  3624.             temp[1] = ' ';
  3625.             temp[2] = '-';
  3626.             temp[3] = ' ';
  3627.             for (i=0; i<NumMenus; i++) {
  3628.                 WinSendDlgItemMsg( hWnd, STARTUP_ITEMLIST, LM_INSERTITEM, MPFROMSHORT( LIT_END ), MenuName[i] );
  3629.                 for (j=0; j<NumItems[i]; j++)
  3630.                     if (Menus[i][j]->ItemName[0] != '\0') {
  3631.                         temp[4] = '\0';
  3632.                         strcat(temp, Menus[i][j]->ItemName);
  3633.                         WinSendDlgItemMsg( hWnd, STARTUP_ITEMLIST, LM_INSERTITEM, MPFROMSHORT( LIT_END ), temp );
  3634.                         }
  3635.                 }
  3636.  
  3637.             WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_DELETEALL, 0, 0);
  3638.             for( i = 0; i< numStartItems; i++)
  3639.                 WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), Menus[(StartUpMenu[i])][(StartUpItem[i])]->ItemName );
  3640.  
  3641.             WinCheckButton( hWnd, STARTUP_LAUNCH, DoStartUpList );
  3642.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3643.             }
  3644.         //----------------------------------------------------------------------
  3645.         //----------------------------------------------------------------------
  3646.         case WM_CONTROL:
  3647.         {
  3648.             if (SHORT2FROMMP(mp1)==BN_CLICKED) {
  3649.                 BOOLEAN option = FALSE;
  3650.                 if (WinQueryButtonCheckstate( hWnd, BKGND_TILED))
  3651.                     option = TRUE;
  3652.                 WinEnableControl( hWnd, BKGND_TILENUMBER, option );
  3653.                 WinEnableControl( hWnd, BKGND_TILENUMBERTEXT, option );
  3654.                 WinEnableControl( hWnd, BKGND_LESS, option );
  3655.                 WinEnableControl( hWnd, BKGND_MORE, option );
  3656.                 }
  3657.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3658.         }
  3659.         //----------------------------------------------------------------------
  3660.         //----------------------------------------------------------------------
  3661.         case WM_COMMAND:
  3662.         {
  3663.             USHORT command = SHORT1FROMMP(mp1);
  3664.             switch( command )
  3665.                 {
  3666.                 //--------------------------------------------------------------
  3667.                 //--------------------------------------------------------------
  3668.                 case STARTUP_ADD: {
  3669.  
  3670.                     if (numStartItems == MAXSTARTITEMS)
  3671.                         WinMessageBox( HWND_DESKTOP, hwndFrame, MSG41, MSG42, 0,
  3672.                                        MB_MOVEABLE|MB_ERROR|MB_OK);
  3673.                     else {
  3674.                         char buffer[MAXITEMNAMELENGTH + 8];
  3675.                         SHORT i,j;
  3676.                         BOOL found = FALSE;
  3677.                         SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, STARTUP_ITEMLIST,
  3678.                                                                               LM_QUERYSELECTION,
  3679.                                                                               MPFROM2SHORT( LIT_FIRST, 0 ),
  3680.                                                                               0 ) );
  3681.                         if (itemSelected == LIT_NONE) {
  3682.                             WinMessageBox( HWND_DESKTOP, hwndFrame, MSG43, MSG44, 0,
  3683.                                            MB_MOVEABLE|MB_ERROR|MB_OK);
  3684.                             return 0;
  3685.                             }
  3686.  
  3687.                         for( i=0; i<NumMenus; i++)
  3688.                             for( j=0; j<NumItems[i]; j++) {
  3689.                                 SHORT1FROMMP( WinSendDlgItemMsg( hWnd, STARTUP_ITEMLIST,
  3690.                                                          LM_QUERYITEMTEXT,
  3691.                                                          MPFROM2SHORT( itemSelected, sizeof(buffer) ),
  3692.                                                          &buffer ) );
  3693.                                 if (strcmp(&(buffer[4]),Menus[i][j]->ItemName)==0) {
  3694.                                     StartUpMenu[ numStartItems ] = i;
  3695.                                     StartUpItem[ numStartItems ] = j;
  3696.                                     numStartItems++;
  3697.                                     WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), Menus[i][j]->ItemName );
  3698.                                     found = TRUE;
  3699.                                     }
  3700.                                 }
  3701.  
  3702.                             if (!found)
  3703.                                 WinMessageBox( HWND_DESKTOP, hwndFrame, MSG45, MSG46, 0,
  3704.                                                MB_MOVEABLE|MB_ERROR|MB_OK);
  3705.                         }
  3706.                     return 0;
  3707.                     }
  3708.                 //--------------------------------------------------------------
  3709.                 //--------------------------------------------------------------
  3710.                 case STARTUP_REMOVE: {
  3711.                     SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS,
  3712.                                                                      LM_QUERYSELECTION,
  3713.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  3714.                                                                      0 ) );
  3715.                     SHORT i;
  3716.  
  3717.                     if (itemSelected != LIT_NONE) {
  3718.                         for (i=itemSelected+1; i<numStartItems; i++) {
  3719.                             StartUpMenu[i-1] = StartUpMenu[i];
  3720.                             StartUpItem[i-1] = StartUpItem[i];
  3721.                             }
  3722.                         numStartItems--;
  3723.                         WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_DELETEALL, 0, 0);
  3724.                         for( i = 0; i< numStartItems; i++)
  3725.                             WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), Menus[(StartUpMenu[i])][(StartUpItem[i])]->ItemName );
  3726.  
  3727.                         if (itemSelected == numStartItems)
  3728.                             WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_SELECTITEM,
  3729.                                                MPFROM2SHORT( numStartItems-1, 0 ),
  3730.                                                MPFROM2SHORT( TRUE, 0 ) );
  3731.                         else
  3732.                             WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_SELECTITEM,
  3733.                                                MPFROM2SHORT( itemSelected, 0 ),
  3734.                                                MPFROM2SHORT( TRUE, 0 ) );
  3735.                         }
  3736.  
  3737.                     return 0;
  3738.                     }
  3739.                 //--------------------------------------------------------------
  3740.                 //--------------------------------------------------------------
  3741.                 case STARTUP_CLEARALL: {
  3742.                     WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_DELETEALL, 0, 0);
  3743.                     numStartItems = 0;
  3744.                     return 0;
  3745.                     }
  3746.                 //--------------------------------------------------------------
  3747.                 //--------------------------------------------------------------
  3748.                 case STARTUP_MOVEDOWN: {
  3749.                     SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS,
  3750.                                                                      LM_QUERYSELECTION,
  3751.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  3752.                                                                      0 ) );
  3753.                     if ((itemSelected < (numStartItems-1)) && (itemSelected != LIT_NONE)) {
  3754.                         SHORT z;
  3755.                         SHORT i;
  3756.  
  3757.                         z = StartUpMenu[itemSelected+1];
  3758.                         StartUpMenu[itemSelected+1] = StartUpMenu[itemSelected];
  3759.                         StartUpMenu[itemSelected] = z;
  3760.  
  3761.                         z = StartUpItem[itemSelected+1];
  3762.                         StartUpItem[itemSelected+1] = StartUpItem[itemSelected];
  3763.                         StartUpItem[itemSelected] = z;
  3764.  
  3765.                         WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_DELETEALL, 0, 0);
  3766.                         for( i = 0; i< numStartItems; i++)
  3767.                             WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), Menus[(StartUpMenu[i])][(StartUpItem[i])]->ItemName );
  3768.  
  3769.                         WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_SELECTITEM,
  3770.                                            MPFROM2SHORT( itemSelected+1, 0 ),
  3771.                                            MPFROM2SHORT( TRUE, 0 ) );
  3772.                         }
  3773.                     return 0;
  3774.                     }
  3775.                 //--------------------------------------------------------------
  3776.                 //--------------------------------------------------------------
  3777.                 case STARTUP_MOVEUP: {
  3778.                     SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS,
  3779.                                                                      LM_QUERYSELECTION,
  3780.                                                                      MPFROM2SHORT( LIT_FIRST, 0 ),
  3781.                                                                      0 ) );
  3782.                     if ((itemSelected > 0) && (itemSelected != LIT_NONE)) {
  3783.                         SHORT z;
  3784.                         SHORT i;
  3785.  
  3786.                         z = StartUpMenu[itemSelected-1];
  3787.                         StartUpMenu[itemSelected-1] = StartUpMenu[itemSelected];
  3788.                         StartUpMenu[itemSelected] = z;
  3789.  
  3790.                         z = StartUpItem[itemSelected-1];
  3791.                         StartUpItem[itemSelected-1] = StartUpItem[itemSelected];
  3792.                         StartUpItem[itemSelected] = z;
  3793.  
  3794.                         WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_DELETEALL, 0, 0);
  3795.                         for( i = 0; i< numStartItems; i++)
  3796.                             WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), Menus[(StartUpMenu[i])][(StartUpItem[i])]->ItemName );
  3797.  
  3798.                         WinSendDlgItemMsg( hWnd, STARTUP_CURRITEMS, LM_SELECTITEM,
  3799.                                            MPFROM2SHORT( itemSelected-1, 0 ),
  3800.                                            MPFROM2SHORT( TRUE, 0 ) );
  3801.                         }
  3802.                     return 0;
  3803.                     }
  3804.                 //--------------------------------------------------------------
  3805.                 // if they pressed OK, then save the data in the dialog as an
  3806.                 // item that we can now launch from the fileBar.
  3807.                 //--------------------------------------------------------------
  3808.                 case DID_OK: {
  3809.                     DoStartUpList = WinQueryButtonCheckstate( hWnd, STARTUP_LAUNCH);
  3810.                     WinDismissDlg( hWnd, TRUE );
  3811.                     return 0;
  3812.                     }
  3813.             }
  3814.         }
  3815.         //----------------------------------------------------------------------
  3816.         // if nothing further we want to intercept, pass message onto system
  3817.         //----------------------------------------------------------------------
  3818.         default:
  3819.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3820.     }
  3821. }
  3822.  
  3823.  
  3824. ////////////////////////////////////////////////////////////////////////////////
  3825. // execute start up list of applications
  3826. ////////////////////////////////////////////////////////////////////////////////
  3827. VOID ExecuteStartUpList( VOID )
  3828. {
  3829.      SHORT i;
  3830.  
  3831.      if (DoStartUpList)
  3832.          for (i=0; i<numStartItems; i++)
  3833.              startApplication( StartUpMenu[i], StartUpItem[i] );
  3834.      startUp = FALSE;
  3835. }
  3836.  
  3837.  
  3838. ////////////////////////////////////////////////////////////////////////////////
  3839. // update the buttons of the calendar to reflect current month structure
  3840. ////////////////////////////////////////////////////////////////////////////////
  3841. VOID updateCalendar( HWND hWnd )
  3842. {
  3843.     LONG backgroundColor = CLR_YELLOW;
  3844.     LONG foregroundColor = CLR_BLACK;
  3845.     CHAR temp[50];
  3846.     int origDay;
  3847.     int origMonth;
  3848.     struct tm *time_now;
  3849.     time_t currentTime;
  3850.     short i;
  3851.     short numDaysInMonth;
  3852.  
  3853.     time(¤tTime);
  3854.     time_now = localtime( ¤tTime );
  3855.     numDaysInMonth = numberOfDaysInMonth(month, year);
  3856.  
  3857.     origDay = time_now->tm_mday;
  3858.     origMonth = time_now->tm_mon;
  3859.     time_now->tm_mon = month;
  3860.     time_now->tm_year= year;
  3861.  
  3862.     strftime( temp, sizeof(temp), " %B - %Y ", time_now);
  3863.     WinSetDlgItemText( hWnd, 550, temp );
  3864.  
  3865.     for( i=500; i<543; i++) {
  3866.         WinRemovePresParam( WinWindowFromID(hWnd, i), PP_BACKGROUNDCOLORINDEX );
  3867.         WinRemovePresParam( WinWindowFromID(hWnd, i), PP_FOREGROUNDCOLORINDEX );
  3868.         }
  3869.  
  3870.     for( i=0; i<startDay; i++) {
  3871.         WinSetDlgItemText( hWnd, i+500, "" );
  3872.         WinEnableControl( hWnd, i+500, FALSE );
  3873.         }
  3874.  
  3875.     if (month==origMonth) {
  3876.         WinSetPresParam( WinWindowFromID(hWnd, origDay+startDay+499), PP_BACKGROUNDCOLORINDEX, sizeof(LONG), (PVOID)&backgroundColor );
  3877.         WinSetPresParam( WinWindowFromID(hWnd, origDay+startDay+499), PP_FOREGROUNDCOLORINDEX, sizeof(LONG), (PVOID)&foregroundColor );
  3878.         }
  3879.  
  3880.     for( i=1; i<=numDaysInMonth; i++) {
  3881.         sprintf(temp, "%d", i);
  3882.         WinEnableControl( hWnd, i+startDay+500-1, TRUE );
  3883.         WinSetDlgItemText( hWnd, i+startDay+500-1, temp );
  3884.         }
  3885.  
  3886.     for( i=numDaysInMonth+startDay+500; i<543; i++) {
  3887.         WinSetDlgItemText( hWnd, i, "" );
  3888.         WinEnableControl( hWnd, i, FALSE );
  3889.         }
  3890. }
  3891.  
  3892.  
  3893. ////////////////////////////////////////////////////////////////////////////////
  3894. // return # of days in # (even checking for leap year)
  3895. ////////////////////////////////////////////////////////////////////////////////
  3896. BYTE numberOfDaysInMonth(int month, int year)
  3897. {
  3898.     if (((1900+year) % 4) || (month != 1))
  3899.         return daysInMonth[month];
  3900.     else
  3901.         return daysInMonth[month]+1;    //handle leap year
  3902. }
  3903.  
  3904.  
  3905. ////////////////////////////////////////////////////////////////////////////////
  3906. // display scheduling calendar and let user schedule and revise tasks
  3907. ////////////////////////////////////////////////////////////////////////////////
  3908. MRESULT EXPENTRY schedulerProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  3909. {
  3910.    switch( msg )
  3911.     {
  3912.         //----------------------------------------------------------------------
  3913.         // when the dialog is being initialized, center it on desktop
  3914.         //----------------------------------------------------------------------
  3915.         case WM_INITDLG: {
  3916.             struct tm *time_now;
  3917.             CHAR mesg[24];
  3918.             time_t currentTime;
  3919.             SWP swp;
  3920.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  3921.             WinSetWindowPos( hWnd, (HWND)0,
  3922.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  3923.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  3924.                              0, 0, SWP_MOVE);
  3925.  
  3926.             time(¤tTime);
  3927.             time_now = localtime( ¤tTime );
  3928.             month = time_now->tm_mon;
  3929.             year = time_now->tm_year;
  3930.  
  3931.             startDay = (time_now->tm_wday - (time_now->tm_mday % 7 - 1));
  3932.             if (startDay > 6)
  3933.                 startDay = startDay - 7;
  3934.             else if (startDay < 0)
  3935.                 startDay = startDay + 7;
  3936.             updateCalendar( hWnd );
  3937.  
  3938.             sprintf( mesg, "%s %d %s", MSG47, repeatTime, MSG48 );
  3939.             WinSetDlgItemText( hWnd, REMINDERTIME, mesg );
  3940.  
  3941.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  3942.             }
  3943.         //----------------------------------------------------------------------
  3944.         // process a command message from the dialog box
  3945.         //----------------------------------------------------------------------
  3946.         case WM_COMMAND:
  3947.         {
  3948.             USHORT command = SHORT1FROMMP(mp1);
  3949.  
  3950.             //------------------------------------------------------------------
  3951.             // if the user pressed a day button, show daily schedule window
  3952.             //------------------------------------------------------------------
  3953.             if ((command>=500) && (command<=542)) {
  3954.                 day = command - 500 - startDay;
  3955.                 WinDlgBox(HWND_DESKTOP,
  3956.                           hWnd,
  3957.                           (PFNWP)scheduleProc,
  3958.                           0,
  3959.                           SCHEDULEITEM,
  3960.                           (PVOID)NULL);
  3961.                 return 0;
  3962.                 }
  3963.             //------------------------------------------------------------------
  3964.             // handle user commands
  3965.             //------------------------------------------------------------------
  3966.             switch( command ) {
  3967.                 //------------------------------------------------------------------
  3968.                 // show all currently scheduled tasks
  3969.                 //------------------------------------------------------------------
  3970.                 case SHOWALL: {
  3971.                     WinDlgBox(HWND_DESKTOP,
  3972.                               hWnd,
  3973.                               (PFNWP)showAllItemsProc,
  3974.                               0,
  3975.                               SHOWALLITEMS,
  3976.                               (PVOID)NULL);
  3977.                     return 0;
  3978.                     }
  3979.                 //--------------------------------------------------------------
  3980.                 // reduce amount of time between reminder sounds
  3981.                 //--------------------------------------------------------------
  3982.                 case LESSTIME: {
  3983.                     char mesg[24];
  3984.                     if (repeatTime>0)
  3985.                         repeatTime--;
  3986.                     sprintf( mesg, "%s %d %s", MSG47, repeatTime, MSG48 );
  3987.                     WinSetDlgItemText( hWnd, REMINDERTIME, mesg );
  3988.                     return 0;
  3989.                     }
  3990.                 //--------------------------------------------------------------
  3991.                 // increase amount of time between reminder sounds
  3992.                 //--------------------------------------------------------------
  3993.                 case MORETIME: {
  3994.                     char mesg[24];
  3995.                     if (repeatTime<32767)
  3996.                         repeatTime++;
  3997.                     sprintf( mesg, "%s %d %s", MSG47, repeatTime, MSG48 );
  3998.                     WinSetDlgItemText( hWnd, REMINDERTIME, mesg );
  3999.                     return 0;
  4000.                     }
  4001.                 //--------------------------------------------------------------
  4002.                 // go back 1 month
  4003.                 //--------------------------------------------------------------
  4004.                 case 551: {
  4005.                     month--;
  4006.                     if (month < 0) {
  4007.                         month = 11;
  4008.                         year--;
  4009.                         }
  4010.  
  4011.                     startDay = startDay - numberOfDaysInMonth(month, year) % 7;
  4012.  
  4013.                     if (startDay > 6)
  4014.                         startDay = startDay - 7;
  4015.                     if (startDay < 0)
  4016.                         startDay = startDay + 7;
  4017.  
  4018.                     updateCalendar( hWnd );
  4019.                     return 0;
  4020.                     }
  4021.                 //--------------------------------------------------------------
  4022.                 // advance 1 month
  4023.                 //--------------------------------------------------------------
  4024.                 case 553: {
  4025.                     SHORT oldMonth = month;
  4026.                     SHORT oldYear = year;
  4027.  
  4028.                     month++;
  4029.                     if (month > 11) {
  4030.                         month = 0;
  4031.                         year++;
  4032.                         }
  4033.  
  4034.                     startDay = (startDay + numberOfDaysInMonth(oldMonth, oldYear)) % 7;
  4035.                     if (startDay > 6)
  4036.                         startDay = startDay - 7;
  4037.                     if (startDay < 0)
  4038.                         startDay = startDay + 7;
  4039.  
  4040.                     updateCalendar( hWnd );
  4041.                     return 0;
  4042.                     }
  4043.                 //--------------------------------------------------------------
  4044.                 // go back to current month
  4045.                 //--------------------------------------------------------------
  4046.                 case 552: {
  4047.                     time_t currentTime;
  4048.                     struct tm *time_now;
  4049.  
  4050.                     time(¤tTime);
  4051.                     time_now = localtime( ¤tTime );
  4052.                     month = time_now->tm_mon;
  4053.                     year = time_now->tm_year;
  4054.  
  4055.                     startDay = time_now->tm_wday - (time_now->tm_mday % 7 - 1);
  4056.                     if (startDay > 6)
  4057.                         startDay = startDay - 7;
  4058.                     if (startDay < 0)
  4059.                         startDay = startDay + 7;
  4060.  
  4061.                     updateCalendar( hWnd );
  4062.                     return 0;
  4063.                     }
  4064.                 //--------------------------------------------------------------
  4065.                 // user pressed OK, cancel dialog
  4066.                 //--------------------------------------------------------------
  4067.                 case DID_OK: {
  4068.                     WinDismissDlg( hWnd, TRUE );
  4069.                     return 0;
  4070.                 }
  4071.             }
  4072.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4073.         }
  4074.         //----------------------------------------------------------------------
  4075.         // if nothing further we want to intercept, pass message onto system
  4076.         //----------------------------------------------------------------------
  4077.         default:
  4078.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4079.     }
  4080. }
  4081.  
  4082.  
  4083. ////////////////////////////////////////////////////////////////////////////////
  4084. ////////////////////////////////////////////////////////////////////////////////
  4085. MRESULT EXPENTRY showAllItemsProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  4086. {
  4087.    switch( msg )
  4088.     {
  4089.         //----------------------------------------------------------------------
  4090.         // when the dialog is being initialized, center it on desktop
  4091.         //----------------------------------------------------------------------
  4092.         case WM_INITDLG: {
  4093.             USERMENUITEM* userItem;
  4094.             ALARMS* alarm;
  4095.             CHAR temp[64+MAXACTIONSTRINGLENGTH];
  4096.             CHAR s[MAXACTIONSTRINGLENGTH+11];
  4097.             SWP swp;
  4098.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  4099.             WinSetWindowPos( hWnd, (HWND)0,
  4100.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  4101.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  4102.                              0, 0, SWP_MOVE);
  4103.  
  4104.             sprintf(temp, "%d %s %d %s)", numAlarms, MSG49, MAXALARMS, MSG50 );
  4105.             WinSetWindowText( hWnd, temp );
  4106.  
  4107.             WinSendDlgItemMsg( hWnd, SHOWITEMS, LM_DELETEALL, MPFROMSHORT( LIT_END ), temp );
  4108.             for( short i = 0; i< numAlarms; i++) {
  4109.                 alarm = alarmPtr[i];
  4110.                 CHAR c = 'a';
  4111.                 //BYTE hour = alarm[i].AlarmHour;
  4112.                 BYTE hour = alarm->AlarmHour;
  4113.  
  4114.                 //if (alarm[i].options & SCHEDULE_LAUNCHAPP) {
  4115.                 if (alarm->options & SCHEDULE_LAUNCHAPP) {
  4116.                     short j = 10;
  4117.                     short k = 0;
  4118.                     strcpy(s, MSG51);
  4119. //                    while ((ItemName[((int)alarm[i].ActionToDo[0])][((int)alarm[i].ActionToDo[1])][k])!='\0')
  4120. //                        if ((ItemName[((int)alarm[i].ActionToDo[0])][((int)alarm[i].ActionToDo[1])][k])=='~')
  4121.                     userItem = Menus[((int)alarm->ActionToDo[0])][((int)alarm->ActionToDo[1])];
  4122.                     while (userItem->ItemName[k] != '\0')
  4123.                         if (userItem->ItemName[k] == '~')
  4124.                             k++;
  4125.                         else
  4126. //                            s[j++] = ItemName[((int)alarm[i].ActionToDo[0])][((int)alarm[i].ActionToDo[1])][k++];
  4127.                             s[j++] = userItem->ItemName[k++];
  4128.                         s[j] = '\0';
  4129.                     }
  4130.                 else
  4131.                     //strcpy(s, alarm[i].ActionToDo);
  4132.                     strcpy(s, alarm->ActionToDo);
  4133.  
  4134.                 //if (alarm[i].AlarmHour>11)
  4135.                 if (alarm->AlarmHour>11)
  4136.                     c='p';
  4137.                 if (!(hour = hour % 12))
  4138.                     hour = 12;
  4139.  
  4140.                 sprintf( temp, "%2d:%2d%cm (%2d:%2d) -- %d/%d/%d (%d/%d/%d) -- %s", hour,
  4141.                                                                     alarm->AlarmMinute,
  4142.                                                                     c,
  4143.                                                                     alarm->AlarmHour,
  4144.                                                                     alarm->AlarmMinute,
  4145.                                                                     alarm->AlarmMonth+1,
  4146.                                                                     alarm->AlarmDay+1,
  4147.                                                                     alarm->AlarmYear,
  4148.                                                                     alarm->AlarmDay+1,
  4149.                                                                     alarm->AlarmMonth+1,
  4150.                                                                     alarm->AlarmYear,
  4151.                                                                     s );
  4152. /*
  4153.                 sprintf( temp, "%2d:%2d%cm (%2d:%2d) -- %d/%d/%d (%d/%d/%d) -- %s", hour,
  4154.                                                                     alarm[i].AlarmMinute,
  4155.                                                                     c,
  4156.                                                                     alarm[i].AlarmHour,
  4157.                                                                     alarm[i].AlarmMinute,
  4158.                                                                     alarm[i].AlarmMonth+1,
  4159.                                                                     alarm[i].AlarmDay+1,
  4160.                                                                     alarm[i].AlarmYear,
  4161.                                                                     alarm[i].AlarmDay+1,
  4162.                                                                     alarm[i].AlarmMonth+1,
  4163.                                                                     alarm[i].AlarmYear,
  4164.                                                                     s );
  4165. */
  4166.                 if (temp[3]==' ') {
  4167.                     temp[3] = '0';
  4168.                     temp[12]= '0';
  4169.                     }
  4170.  
  4171.                 WinSendDlgItemMsg( hWnd, SHOWITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), temp );
  4172.                 }
  4173.  
  4174.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4175.             }
  4176.         //----------------------------------------------------------------------
  4177.         //----------------------------------------------------------------------
  4178.         case WM_CONTROL:
  4179.         {
  4180.             if (SHORT2FROMMP(mp1)==LN_ENTER) {
  4181.                 SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, SHOWITEMS,
  4182.                                                                       LM_QUERYSELECTION,
  4183.                                                                       MPFROM2SHORT( LIT_FIRST, 0 ),
  4184.                                                                       0 ) );
  4185.  
  4186.                 oldProgType = numAlarms;
  4187.                 numAlarms = 0;
  4188.  
  4189.                 reviseScheduledItem( itemSelected );
  4190.                 sortTimeEntries( oldProgType );
  4191.                 numAlarms = oldProgType;
  4192.                 WinSendMsg( hWnd, WM_INITDLG, 0, 0 );
  4193.                 WinSendDlgItemMsg( hWnd, SHOWITEMS, LM_SELECTITEM,
  4194.                                    MPFROM2SHORT( itemSelected, 0 ),
  4195.                                    MPFROM2SHORT( TRUE, 0 ) );
  4196.                 return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4197.                 }
  4198.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4199.         }
  4200.         //----------------------------------------------------------------------
  4201.         // if we receive any system message, dismiss the dialog box
  4202.         //----------------------------------------------------------------------
  4203.         case WM_COMMAND:
  4204.         {
  4205.             if (SHORT1FROMMP(mp1)==DID_OK)
  4206.                 WinDismissDlg( hWnd, TRUE );
  4207.             return 0;
  4208.         }
  4209.         //----------------------------------------------------------------------
  4210.         // if nothing further we want to intercept, pass message onto system
  4211.         //----------------------------------------------------------------------
  4212.         default:
  4213.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4214.     }
  4215. }
  4216.  
  4217.  
  4218. ////////////////////////////////////////////////////////////////////////////////
  4219. ////////////////////////////////////////////////////////////////////////////////
  4220. MRESULT EXPENTRY scheduleProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  4221. {
  4222.     switch( msg )
  4223.     {
  4224.         //----------------------------------------------------------------------
  4225.         // when the dialog is being initialized, center it on desktop
  4226.         //----------------------------------------------------------------------
  4227.         case WM_INITDLG: {
  4228.             CHAR temp[MAXACTIONSTRINGLENGTH+32];
  4229.             SWP swp;
  4230.             SHORT i;
  4231.             ALARMS* alarm;
  4232.             USERMENUITEM* menuItem;
  4233.  
  4234.             // disable alarms while editing calendar
  4235.             oldProgType = numAlarms;
  4236.             numAlarms = 0;
  4237.  
  4238.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  4239.             WinSetWindowPos( hWnd, (HWND)0,
  4240.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  4241.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  4242.                              0, 0, SWP_MOVE);
  4243.  
  4244.             sprintf( temp, "%s %d/%d/%4d...", MSG52, month+1, day+1, 1900+year);
  4245.             WinSetWindowText( hWnd, temp );
  4246.  
  4247.             WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS, LM_DELETEALL, MPFROMSHORT( LIT_END ), temp );
  4248.  
  4249.             for( i = 0; i< oldProgType; i++) {
  4250.                 alarm = alarmPtr[i];
  4251.                 if (alarm->AlarmDay == day)
  4252.                   if (alarm->AlarmMonth == month)
  4253.                     if (alarm->AlarmYear == year) {
  4254.                         CHAR c = 'a';
  4255.                         CHAR s[11+MAXACTIONSTRINGLENGTH];
  4256.                         BYTE hour = alarm->AlarmHour;
  4257.  
  4258.                         if (alarm->options & SCHEDULE_LAUNCHAPP) {
  4259.                             short j = 10;
  4260.                             short k = 0;
  4261.                             strcpy(s, MSG51);
  4262.                             menuItem = Menus[((int)alarmPtr[i]->ActionToDo[0])][((int)alarmPtr[i]->ActionToDo[1])];
  4263.                             while (menuItem->ItemName[k] !='\0')
  4264.                                 if (menuItem->ItemName[k] =='~')
  4265.                                     k++;
  4266.                                 else
  4267.                                     s[j++] = menuItem->ItemName[k++];
  4268.                             s[j] = '\0';
  4269.                             }
  4270.                         else
  4271.                             strcpy(s, alarm->ActionToDo);
  4272.  
  4273.                         if (alarm->AlarmHour>11)
  4274.                             c='p';
  4275.                         if (!(hour = hour % 12))
  4276.                             hour = 12;
  4277.  
  4278.                         sprintf( temp, "%2d:%2d%cm (%2d:%2d) -- %s", hour,
  4279.                                                                     alarm->AlarmMinute,
  4280.                                                                     c,
  4281.                                                                     alarm->AlarmHour,
  4282.                                                                     alarm->AlarmMinute,
  4283.                                                                     s );
  4284.                         if (temp[3]==' ') {
  4285.                             temp[3] = '0';
  4286.                             temp[12]= '0';
  4287.                             }
  4288.  
  4289.  
  4290.                         WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS, LM_INSERTITEM, MPFROMSHORT( LIT_END ), temp );
  4291.                         }
  4292.                 }
  4293.  
  4294.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4295.             }
  4296.         //----------------------------------------------------------------------
  4297.         //----------------------------------------------------------------------
  4298.         case WM_CONTROL:
  4299.         {
  4300.             if ((SHORT1FROMMP(mp1)==SCHEDULEDITEMS) && (SHORT2FROMMP(mp1)==LN_ENTER))
  4301.                 return WinSendMsg( hWnd, WM_COMMAND, MPFROM2SHORT( REVISEITEM, 0 ), mp2 );
  4302.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4303.         }
  4304.         //----------------------------------------------------------------------
  4305.         //----------------------------------------------------------------------
  4306.         case WM_COMMAND:
  4307.         {
  4308.             USHORT command = SHORT1FROMMP(mp1);
  4309.  
  4310.             //------------------------------------------------------------------
  4311.             //------------------------------------------------------------------
  4312.             if ( command==DELETEITEM ) {
  4313.                 BOOL continueOn = TRUE;
  4314.                 SHORT index = 0;
  4315.                 SHORT item = 0;
  4316.                 SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS,
  4317.                                                                       LM_QUERYSELECTION,
  4318.                                                                       MPFROM2SHORT( LIT_FIRST, 0 ),
  4319.                                                                       0 ) );
  4320.                 if (itemSelected==LIT_NONE) {
  4321.                     WinMessageBox( HWND_DESKTOP, hwndFrame,
  4322.                                    MSG53,
  4323.                                    MSG54, 0,
  4324.                                    MB_MOVEABLE|MB_ERROR|MB_OK);
  4325.                     return 0;
  4326.                     }
  4327.  
  4328.                 if (WinMessageBox( HWND_DESKTOP, hwndFrame,
  4329.                                    MSG55,
  4330.                                    MSG54, 0,
  4331.                                    MB_MOVEABLE|MB_ICONQUESTION|MB_YESNO) == MBID_NO)
  4332.                     return 0;
  4333.  
  4334.                 itemSelected++;
  4335.                 while (continueOn) {
  4336.                     if ((alarmPtr[index]->AlarmYear  == (BYTE)(year%100)) &&
  4337.                         (alarmPtr[index]->AlarmMonth == (BYTE)(month%14)) &&
  4338.                         (alarmPtr[index]->AlarmDay   == (BYTE)(day%40))) {
  4339.                             item++;
  4340.                             if (item == itemSelected)
  4341.                                 continueOn = FALSE;
  4342.                             }
  4343.                     index++;
  4344.                     }
  4345.  
  4346.                 delete alarmPtr[index-1];
  4347.                 {
  4348.                     struct ALARMS* tmp;
  4349.                     //struct ALARMS tmp;
  4350.                     for ( item=index-1; item<MAXALARMS-1; item++) {
  4351.                         tmp = alarmPtr[item];
  4352.                         alarmPtr[item]   = alarmPtr[item+1];
  4353.                         alarmPtr[item+1] = tmp;
  4354.                         }
  4355.                 }
  4356.                 numAlarms = oldProgType-1;
  4357.                 sortTimeEntries( numAlarms );
  4358.                 WinSendMsg( hWnd, WM_INITDLG, 0, 0 );
  4359.                 if (index-1 >= oldProgType)
  4360.                     WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS, LM_SELECTITEM,
  4361.                                        MPFROM2SHORT( oldProgType-1, 0 ),
  4362.                                        MPFROM2SHORT( TRUE, 0 ) );
  4363.                 else
  4364.                     WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS, LM_SELECTITEM,
  4365.                                        MPFROM2SHORT( index-1, 0 ),
  4366.                                        MPFROM2SHORT( TRUE, 0 ) );
  4367.                 return 0;
  4368.                 }
  4369.             //------------------------------------------------------------------
  4370.             //------------------------------------------------------------------
  4371.             if ( command==ADDITEM ) {
  4372.                 ALARMS* alarm;
  4373.                 SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS,
  4374.                                                                       LM_QUERYSELECTION,
  4375.                                                                       MPFROM2SHORT( LIT_FIRST, 0 ),
  4376.                                                                       0 ) );
  4377.                 if (oldProgType == MAXALARMS) {
  4378.                     WinMessageBox( HWND_DESKTOP, hwndFrame,
  4379.                                    MSG56,
  4380.                                    MSG57, 0,
  4381.                                    MB_MOVEABLE|MB_ERROR|MB_OK);
  4382.                     return 0;
  4383.                     }
  4384.  
  4385.                 alarmPtr[oldProgType] = new ALARMS;
  4386.                 alarm = alarmPtr[oldProgType];
  4387.                 alarm->AlarmYear = (BYTE)(year%100);
  4388.                 alarm->AlarmMonth = (BYTE)(month%14);
  4389.                 alarm->AlarmDay = (BYTE)(day%40);
  4390.                 alarm->AlarmHour = 0;
  4391.                 alarm->AlarmMinute = 0;
  4392.                 alarm->options = SCHEDULE_USEWAVFILE | SCHEDULE_USEWAVFILE;
  4393.                 alarm->ActionToDo[0] = 0;
  4394.                 alarm->ReminderWAV[0] = 0;
  4395.                 oldProgType++;
  4396.                 reviseScheduledItem( oldProgType-1 );
  4397.                 sortTimeEntries( oldProgType );
  4398.                 numAlarms = oldProgType;
  4399.                 WinSendMsg( hWnd, WM_INITDLG, 0, 0 );
  4400.                 WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS, LM_SELECTITEM,
  4401.                                    MPFROM2SHORT( itemSelected, 0 ),
  4402.                                    MPFROM2SHORT( TRUE, 0 ) );
  4403.                 return 0;
  4404.                 }
  4405.             //------------------------------------------------------------------
  4406.             //------------------------------------------------------------------
  4407.             if (( command==REVISEITEM ) || (command==LN_ENTER)) {
  4408.                 BOOL continueOn = TRUE;
  4409.                 SHORT index = 0;
  4410.                 SHORT item = 0;
  4411.                 SHORT itemSelected = 1 + SHORT1FROMMP( WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS,
  4412.                                                                           LM_QUERYSELECTION,
  4413.                                                                           MPFROM2SHORT( LIT_FIRST, 0 ),
  4414.                                                                           0 ) );
  4415.  
  4416.                 if ( (itemSelected-1) == LIT_NONE ) {
  4417.                     WinMessageBox( HWND_DESKTOP, hwndFrame,
  4418.                                    MSG58,
  4419.                                    MSG59, 0,
  4420.                                    MB_MOVEABLE|MB_ERROR|MB_OK);
  4421.                     return 0;
  4422.                     }
  4423.  
  4424.                 while (continueOn) {
  4425.                     if ((alarmPtr[index]->AlarmYear  == (BYTE)(year%100)) &&
  4426.                         (alarmPtr[index]->AlarmMonth == (BYTE)(month%14)) &&
  4427.                         (alarmPtr[index]->AlarmDay   == (BYTE)(day%40))) {
  4428.                             item++;
  4429.                             if (item == itemSelected)
  4430.                                 continueOn = FALSE;
  4431.                             }
  4432.                     index++;
  4433.                     }
  4434.                 reviseScheduledItem( index-1 );
  4435.                 sortTimeEntries( oldProgType );
  4436.                 numAlarms = oldProgType;
  4437.                 WinSendMsg( hWnd, WM_INITDLG, 0, 0 );
  4438.                 WinSendDlgItemMsg( hWnd, SCHEDULEDITEMS, LM_SELECTITEM,
  4439.                                    MPFROM2SHORT( itemSelected-1, 0 ),
  4440.                                    MPFROM2SHORT( TRUE, 0 ) );
  4441.                 return 0;
  4442.                 }
  4443.             //------------------------------------------------------------------
  4444.             //------------------------------------------------------------------
  4445.             if ( command==DID_OK ) {
  4446.                 WinDismissDlg( hWnd, TRUE );
  4447.                 numAlarms = oldProgType;
  4448.                 return 0;
  4449.                 }
  4450.             }
  4451.         default:
  4452.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4453.     }
  4454. }
  4455.  
  4456.  
  4457. ////////////////////////////////////////////////////////////////////////////////
  4458. ////////////////////////////////////////////////////////////////////////////////
  4459. VOID checkAlarms( SHORT hour, SHORT minute, SHORT month, SHORT day, SHORT year ) {
  4460.     ALARMS* alarm = alarmPtr[0];
  4461.     struct tm *time_now;
  4462.     time_t currentTime;
  4463.  
  4464.     day--;
  4465.     if ((numAlarms == 0) || (alarm->AlarmYear > year ))
  4466.         return;
  4467.     if ((alarm->AlarmYear == year) && (alarm->AlarmMonth > month))
  4468.         return;
  4469.     if ((alarm->AlarmMonth == month) && (alarm->AlarmDay > day))
  4470.         return;
  4471.     if ((alarm->AlarmDay == day) && (alarm->AlarmHour > hour))
  4472.         return;
  4473.     if ((alarm->AlarmHour == hour) && (alarm->AlarmMinute > minute))
  4474.         return;
  4475.  
  4476.     if ((alarm->options & SCHEDULE_LAUNCHAPP) && (!(alarm->options & SCHEDULE_SOUNDONLY)))
  4477.         startApplication( (SHORT)alarm->ActionToDo[0], (SHORT)alarm->ActionToDo[1] );
  4478.     else {
  4479.         currentReminderWavFile = 0;
  4480.         if (alarm->options & SCHEDULE_USEWAVFILE)
  4481.             currentReminderWavFile = alarm->ReminderWAV;
  4482.         if (alarm->options & SCHEDULE_SOUNDONLY)
  4483.             ringChime( currentReminderWavFile );
  4484.         else {
  4485.             oldItemName[0] = TRUE;
  4486.             WinDlgBox(HWND_DESKTOP,
  4487.             hwndFrame,
  4488.             (PFNWP)reminderNoteProc,
  4489.             0,
  4490.             REMINDER_DIALOG,
  4491.             (PVOID)alarm->ActionToDo);
  4492.             if (oldItemName[0]) {
  4493.                 checkAlarms( hour, minute, month, day, year );
  4494.                 return;
  4495.                 }
  4496.             }
  4497.         }
  4498.  
  4499.         // make it so that we reschedule from the current time
  4500.         // and not the time the task was supposed to go off
  4501.         tzset();
  4502.         time(¤tTime);
  4503.         time_now = localtime( ¤tTime );
  4504.  
  4505.         // reschedule or delete note
  4506.         if (alarm->options & SCHEDULE_EVERYHOUR) {
  4507.             alarm->AlarmHour = time_now->tm_hour;
  4508.             alarm->AlarmDay = time_now->tm_mday-1;
  4509.             alarm->AlarmMonth = time_now->tm_mon;
  4510.             alarm->AlarmYear = time_now->tm_year;
  4511.  
  4512.             alarm->AlarmHour++;
  4513.             validateTimeEntry();
  4514.             sortTimeEntries( numAlarms );
  4515.             }
  4516.         else if (alarm->options & SCHEDULE_EVERYDAY) {
  4517.             alarm->AlarmDay = time_now->tm_mday-1;
  4518.             alarm->AlarmMonth = time_now->tm_mon;
  4519.             alarm->AlarmYear = time_now->tm_year;
  4520.             alarm->AlarmDay++;
  4521.             validateTimeEntry();
  4522.             sortTimeEntries( numAlarms );
  4523.             }
  4524.         else if (alarmPtr[0]->options & SCHEDULE_EVERYWEEK) {
  4525.             alarm->AlarmDay = time_now->tm_mday-1;
  4526.             alarm->AlarmMonth = time_now->tm_mon;
  4527.             alarm->AlarmYear = time_now->tm_year;
  4528.             alarm->AlarmDay = alarm->AlarmDay + 7;
  4529.             validateTimeEntry();
  4530.             sortTimeEntries( numAlarms );
  4531.             }
  4532.         else if (alarm->options & SCHEDULE_EVERYMONTH) {
  4533.             alarm->AlarmMonth = time_now->tm_mon;
  4534.             alarm->AlarmYear = time_now->tm_year;
  4535.             alarm->AlarmMonth++;
  4536.             validateTimeEntry();
  4537.             sortTimeEntries( numAlarms );
  4538.             }
  4539.         else if (alarm->options & SCHEDULE_EVERYYEAR) {
  4540.             alarm->AlarmYear = time_now->tm_year;
  4541.             alarm->AlarmYear++;
  4542.             validateTimeEntry();
  4543.             sortTimeEntries( numAlarms );
  4544.             }
  4545.         else {
  4546.         ////// delete the reminder we just performed ///////
  4547.             delete alarm;
  4548.             for (short i=0; i<numAlarms-1; i++)
  4549.                 alarmPtr[i] = alarmPtr[i+1];
  4550.             numAlarms--;
  4551.             }
  4552.         // check to see if another alarm needs to be serviced
  4553.         checkAlarms( hour, minute, month, day, year );
  4554. }
  4555.  
  4556.  
  4557. ////////////////////////////////////////////////////////////////////////////////
  4558. ////////////////////////////////////////////////////////////////////////////////
  4559. VOID validateTimeEntry( VOID )
  4560. {
  4561.     ALARMS* alarm = alarmPtr[0];
  4562.  
  4563.     if (alarm->AlarmMinute > 59) {
  4564.         alarm->AlarmMinute = alarm->AlarmMinute - 60;
  4565.         alarm->AlarmHour++;
  4566.         }
  4567.     if (alarm->AlarmHour > 23) {
  4568.         alarm->AlarmMinute = alarm->AlarmMinute - 24;
  4569.         alarm->AlarmDay++;
  4570.         }
  4571.     if (alarm->AlarmDay > daysInMonth[alarm->AlarmMonth] ) {
  4572.         alarm->AlarmDay = alarm->AlarmDay - daysInMonth[alarm->AlarmMonth];
  4573.         alarm->AlarmMonth++;
  4574.         }
  4575.     if (alarm->AlarmMonth > 11) {
  4576.         alarm->AlarmMonth = alarm->AlarmMonth - 12;
  4577.         alarm->AlarmYear++;
  4578.         }
  4579. }
  4580.  
  4581.  
  4582. ////////////////////////////////////////////////////////////////////////////////
  4583. ////////////////////////////////////////////////////////////////////////////////
  4584. VOID swapTwoTimeEntries( INT entry1, INT entry2 )
  4585. {
  4586.     ALARMS* tmp;
  4587.  
  4588.     tmp = alarmPtr[entry1];
  4589.     alarmPtr[entry1] = alarmPtr[entry2];
  4590.     alarmPtr[entry2] = tmp;
  4591. }
  4592.  
  4593.  
  4594. ////////////////////////////////////////////////////////////////////////////////
  4595. ////////////////////////////////////////////////////////////////////////////////
  4596. VOID sortTimeEntries( INT entries )
  4597. {
  4598.     short i,j;
  4599.  
  4600.     // bubble sort all scheduled events so that closest event tops the list
  4601.     for (i=0; i<entries; i++)
  4602.         for (j=0; j<entries-1; j++)
  4603.             if ( alarmPtr[j]->AlarmMinute > alarmPtr[j+1]->AlarmMinute )
  4604.                 swapTwoTimeEntries(j, j+1);
  4605.     for (i=0; i<entries; i++)
  4606.         for (j=0; j<entries-1; j++)
  4607.             if ( alarmPtr[j]->AlarmHour > alarmPtr[j+1]->AlarmHour )
  4608.                 swapTwoTimeEntries(j, j+1);
  4609.     for (i=0; i<entries; i++)
  4610.         for (j=0; j<entries-1; j++)
  4611.             if ( alarmPtr[j]->AlarmDay > alarmPtr[j+1]->AlarmDay )
  4612.                 swapTwoTimeEntries(j, j+1);
  4613.     for (i=0; i<entries; i++)
  4614.         for (j=0; j<entries-1; j++)
  4615.             if ( alarmPtr[j]->AlarmMonth > alarmPtr[j+1]->AlarmMonth )
  4616.                 swapTwoTimeEntries(j, j+1);
  4617.     for (i=0; i<entries; i++)
  4618.         for (j=0; j<entries-1; j++)
  4619.             if ( alarmPtr[j]->AlarmYear > alarmPtr[j+1]->AlarmYear )
  4620.                 swapTwoTimeEntries(j, j+1);
  4621. }
  4622.  
  4623.  
  4624. ////////////////////////////////////////////////////////////////////////////////
  4625. // reviseScheduledItem - call dialog box to revise a currently scheduled event
  4626. ////////////////////////////////////////////////////////////////////////////////
  4627. VOID reviseScheduledItem( INT itemToEdit )
  4628. {
  4629.     EditItem = itemToEdit;
  4630.     WinDlgBox(HWND_DESKTOP,
  4631.               hwndFrame,
  4632.               (PFNWP)itemProc,
  4633.               0,
  4634.               SCHEDULEITEMDIALOG,
  4635.               (PVOID)0);
  4636.     return;
  4637. }
  4638.  
  4639.  
  4640. ////////////////////////////////////////////////////////////////////////////////
  4641. // displayReminderTime - update display of time in revision dialog box
  4642. ////////////////////////////////////////////////////////////////////////////////
  4643. VOID displayReminderTime( HWND hWnd, INT offset )
  4644. {
  4645.     SHORT hour;
  4646.     CHAR c;
  4647.     CHAR time[16];
  4648.     ALARMS* alarm = alarmPtr[offset];
  4649.  
  4650.     c='a';
  4651.     if (alarm->AlarmHour>11)
  4652.         c='p';
  4653.     if (!(hour = alarm->AlarmHour % 12))
  4654.         hour = 12;
  4655.  
  4656.     sprintf( time, "%2d:%2d%cm (%2d:%2d)", hour,
  4657.                                            alarm->AlarmMinute,
  4658.                                            c,
  4659.                                            alarm->AlarmHour,
  4660.                                            alarm->AlarmMinute);
  4661.     if (time[3]==' ') {
  4662.         time[3] = '0';
  4663.         time[12]= '0';
  4664.         }
  4665.     WinSetDlgItemText( hWnd, TIME_TEXT, (CHAR*)time );
  4666. }
  4667.  
  4668.  
  4669. ////////////////////////////////////////////////////////////////////////////////
  4670. // displayReminderDate - update display of date in revision dialog box
  4671. ////////////////////////////////////////////////////////////////////////////////
  4672. VOID displayReminderDate( HWND hWnd, INT offset )
  4673. {
  4674.     ALARMS* alarm = alarmPtr[offset];
  4675.     CHAR date[24];
  4676.  
  4677.     sprintf( date, " %d/%d/%d (%d/%d/%d) ",  alarm->AlarmMonth+1,
  4678.                                              alarm->AlarmDay+1,
  4679.                                              alarm->AlarmYear,
  4680.                                              alarm->AlarmDay+1,
  4681.                                              alarm->AlarmMonth+1,
  4682.                                              alarm->AlarmYear);
  4683.     WinSetDlgItemText( hWnd, DATETEXT, (CHAR*)date );
  4684. }
  4685.  
  4686.  
  4687. ////////////////////////////////////////////////////////////////////////////////
  4688. ////////////////////////////////////////////////////////////////////////////////
  4689. MRESULT EXPENTRY itemProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  4690. {
  4691.    ALARMS* alarm = alarmPtr[EditItem];
  4692.  
  4693.    switch( msg )
  4694.     {
  4695.         //----------------------------------------------------------------------
  4696.         //----------------------------------------------------------------------
  4697.         case WM_INITDLG: {
  4698.             CHAR s[MAXPATH+11];
  4699.             SWP swp;
  4700.             //ALARMS* alarm = alarmPtr[EditItem];
  4701.  
  4702.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  4703.             WinSetWindowPos( hWnd, (HWND)0,
  4704.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  4705.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  4706.                              0, 0, SWP_MOVE);
  4707.  
  4708.             WinSendDlgItemMsg( hWnd, SOUNDFILE, EM_SETTEXTLIMIT, MPFROMSHORT( MAXACTIONSTRINGLENGTH ), 0 );
  4709.             WinSendDlgItemMsg( hWnd, REMINDER, EM_SETTEXTLIMIT, MPFROMSHORT( MAXACTIONSTRINGLENGTH ), 0 );
  4710.  
  4711.             WinCheckButton( hWnd, DELETEITEM, TRUE );
  4712.             if (alarm->options & SCHEDULE_EVERYHOUR)
  4713.                 WinCheckButton( hWnd, EVERYHOUR, TRUE );
  4714.             else if (alarm->options & SCHEDULE_EVERYDAY)
  4715.                 WinCheckButton( hWnd, EVERYDAY, TRUE );
  4716.             else if (alarm->options & SCHEDULE_EVERYWEEK)
  4717.                 WinCheckButton( hWnd, EVERYWEEK, TRUE );
  4718.             else if (alarm->options & SCHEDULE_EVERYMONTH)
  4719.                 WinCheckButton( hWnd, EVERYMONTH, TRUE );
  4720.             else if (alarm->options & SCHEDULE_EVERYYEAR)
  4721.                 WinCheckButton( hWnd, EVERYYEAR, TRUE );
  4722.  
  4723.             if ( alarm->options & SCHEDULE_USEWAVFILE )
  4724.                 WinCheckButton( hWnd, PLAYSOUND, TRUE );
  4725.             if ( alarm->options & SCHEDULE_SOUNDONLY )
  4726.                 WinCheckButton( hWnd, SOUNDONLY, TRUE );
  4727.  
  4728.             WinSetDlgItemText( hWnd, SOUNDFILE, (CHAR*)alarm->ReminderWAV );
  4729.             displayReminderTime( hWnd, EditItem );
  4730.             displayReminderDate( hWnd, EditItem );
  4731.  
  4732.             if (alarm->options & SCHEDULE_LAUNCHAPP) {
  4733.                 short j = 10;
  4734.                 short k = 0;
  4735.                 USERMENUITEM* menuItem = Menus[((int)alarmPtr[EditItem]->ActionToDo[0])][((int)alarmPtr[EditItem]->ActionToDo[1])];
  4736.  
  4737.                 strcpy(s, MSG51 );
  4738.                 while (menuItem->ItemName[k] !='\0')
  4739.                     if (menuItem->ItemName[k] =='~')
  4740.                         k++;
  4741.                     else
  4742.                         s[j++] = menuItem->ItemName[k++];
  4743.                 s[j] = '\0';
  4744.  
  4745.                 WinSetDlgItemText( hWnd, REMINDER, (CHAR*)s );
  4746.                 WinEnableControl( hWnd, REMINDER, FALSE );
  4747.                 }
  4748.             else {
  4749.                 WinEnableControl( hWnd, REMINDER, TRUE );
  4750.                 WinSetDlgItemText( hWnd, REMINDER, (CHAR*)alarm->ActionToDo );
  4751.                 }
  4752.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4753.             }
  4754.         //----------------------------------------------------------------------
  4755.         //----------------------------------------------------------------------
  4756.         case WM_COMMAND:
  4757.         {
  4758.             USHORT command = SHORT1FROMMP(mp1);
  4759.  
  4760.  
  4761.             switch(command) {
  4762.             //------------------------------------------------------------------
  4763.             //------------------------------------------------------------------
  4764.                 case LAUNCHITEM: {
  4765.                     short tmp = 0;
  4766.  
  4767.                     if (WinQueryButtonCheckstate( hWnd, EVERYHOUR ))
  4768.                         tmp += SCHEDULE_EVERYHOUR;
  4769.                     else if (WinQueryButtonCheckstate( hWnd, EVERYDAY ))
  4770.                         tmp += SCHEDULE_EVERYDAY;
  4771.                     else if (WinQueryButtonCheckstate( hWnd, EVERYWEEK ))
  4772.                         tmp += SCHEDULE_EVERYWEEK;
  4773.                     else if (WinQueryButtonCheckstate( hWnd, EVERYMONTH ))
  4774.                         tmp += SCHEDULE_EVERYMONTH;
  4775.                     else if (WinQueryButtonCheckstate( hWnd, EVERYYEAR ))
  4776.                         tmp += SCHEDULE_EVERYYEAR;
  4777.                     if (WinQueryButtonCheckstate( hWnd, PLAYSOUND ))
  4778.                         tmp += SCHEDULE_USEWAVFILE;
  4779.                     if (WinQueryButtonCheckstate( hWnd, SOUNDONLY ))
  4780.                         tmp += SCHEDULE_SOUNDONLY;
  4781.  
  4782.                     WinDlgBox(HWND_DESKTOP,
  4783.                               hWnd,
  4784.                               (PFNWP)LaunchItemProc,
  4785.                               0,
  4786.                               LAUNCHITEMDIALOG,
  4787.                               (PVOID)0);
  4788.  
  4789.                     if (alarm->options & SCHEDULE_LAUNCHAPP)
  4790.                         tmp = tmp + SCHEDULE_LAUNCHAPP;
  4791.  
  4792.                     alarm->options = tmp;
  4793.                     WinSendMsg( hWnd, WM_INITDLG, 0, 0 );
  4794.                     return 0;
  4795.                     }
  4796.             //------------------------------------------------------------------
  4797.             //------------------------------------------------------------------
  4798.                 case SELECTSOUNDFILE: {
  4799.                     CHAR title[] = MSG60;
  4800.                     HWND hwndDialog;
  4801.                     CHAR oldDir[MAXPATH];
  4802.  
  4803.                     fileDlgInfo.fl = FDS_OPEN_DIALOG|FDS_CENTER;
  4804.                     fileDlgInfo.pszTitle = title;
  4805.                     strcpy( oldDir, fileDlgInfo.szFullFile );
  4806.                     strcat(fileDlgInfo.szFullFile, "*.WAV\0");
  4807.  
  4808.                     hwndDialog = WinFileDlg( HWND_DESKTOP, hWnd, &fileDlgInfo );
  4809.                     if (hwndDialog && (fileDlgInfo.lReturn == DID_OK)) {
  4810.                         strcpy( alarm->ReminderWAV, fileDlgInfo.szFullFile );
  4811.                         strcat( alarm->ReminderWAV, "\0" );
  4812.                         resetFileDialog();
  4813.  
  4814.                         /*
  4815.                         s=0;
  4816.                         while(fileDlgInfo.szFullFile[s]!='\0')
  4817.                             s++;
  4818.                         while((fileDlgInfo.szFullFile[s]!='\\') && (s>=0))
  4819.                             s--;
  4820.  
  4821.                         if (fileDlgInfo.szFullFile[s]=='\\')
  4822.                             fileDlgInfo.szFullFile[s+1]='\0';
  4823.                         else
  4824.                             fileDlgInfo.szFullFile[0]='\0';
  4825.                         */
  4826.  
  4827.                         WinSetDlgItemText( hWnd, SOUNDFILE, alarm->ReminderWAV );
  4828.                         }
  4829.                     else
  4830.                         strcpy( fileDlgInfo.szFullFile, oldDir );
  4831.                     return 0;
  4832.                     }
  4833.             //------------------------------------------------------------------
  4834.             //------------------------------------------------------------------
  4835.                 case DAY_MORE: {
  4836.                     alarm->AlarmDay = (alarm->AlarmDay + 1) % daysInMonth[alarm->AlarmMonth];
  4837.                     displayReminderDate( hWnd, EditItem );
  4838.                     return 0;
  4839.                     }
  4840.             //------------------------------------------------------------------
  4841.             //------------------------------------------------------------------
  4842.                 case DAY_LESS: {
  4843.                     if (alarm->AlarmDay==0)
  4844.                         alarm->AlarmDay = daysInMonth[alarm->AlarmMonth] - 1;
  4845.                     else
  4846.                         alarm->AlarmDay = (alarm->AlarmDay - 1) % daysInMonth[alarm->AlarmMonth];
  4847.                     displayReminderDate( hWnd, EditItem );
  4848.                     return 0;
  4849.                     }
  4850.             //------------------------------------------------------------------
  4851.             //------------------------------------------------------------------
  4852.                 case MONTH_MORE: {
  4853.                     alarm->AlarmMonth = (alarm->AlarmMonth + 1) % 12;
  4854.                     displayReminderDate( hWnd, EditItem );
  4855.                     return 0;
  4856.                     }
  4857.             //------------------------------------------------------------------
  4858.             //------------------------------------------------------------------
  4859.                 case MONTH_LESS: {
  4860.                     if (alarm->AlarmMonth == 0)
  4861.                         alarm->AlarmMonth = 11;
  4862.                     else
  4863.                         alarm->AlarmMonth--;
  4864.                     displayReminderDate( hWnd, EditItem );
  4865.                     return 0;
  4866.                     }
  4867.             //------------------------------------------------------------------
  4868.             //------------------------------------------------------------------
  4869.                 case YEAR_MORE: {
  4870.                     alarm->AlarmYear++;
  4871.                     displayReminderDate( hWnd, EditItem );
  4872.                     return 0;
  4873.                     }
  4874.             //------------------------------------------------------------------
  4875.             //------------------------------------------------------------------
  4876.                 case YEAR_LESS: {
  4877.                     alarm->AlarmYear--;
  4878.                     displayReminderDate( hWnd, EditItem );
  4879.                     return 0;
  4880.                     }
  4881.             //------------------------------------------------------------------
  4882.             //------------------------------------------------------------------
  4883.                 case MINUTE_MORE: {
  4884.                     alarm->AlarmMinute = (alarm->AlarmMinute+1) % 60;
  4885.                     displayReminderTime( hWnd, EditItem );
  4886.                     return 0;
  4887.                     }
  4888.             //------------------------------------------------------------------
  4889.             //------------------------------------------------------------------
  4890.                 case MINUTE_LESS: {
  4891.                     if (alarm->AlarmMinute == 0)
  4892.                         alarm->AlarmMinute = 59;
  4893.                     else
  4894.                         alarm->AlarmMinute = (alarm->AlarmMinute-1) % 60;
  4895.                     displayReminderTime( hWnd, EditItem );
  4896.                     return 0;
  4897.                     }
  4898.             //------------------------------------------------------------------
  4899.             //------------------------------------------------------------------
  4900.                 case HOUR_MORE: {
  4901.                     alarm->AlarmHour = (alarm->AlarmHour+1) % 24;
  4902.                     displayReminderTime( hWnd, EditItem );
  4903.                     return 0;
  4904.                     }
  4905.             //------------------------------------------------------------------
  4906.             //------------------------------------------------------------------
  4907.                 case HOUR_LESS: {
  4908.                     if (alarm->AlarmHour == 0)
  4909.                         alarm->AlarmHour = 23;
  4910.                     else
  4911.                         alarm->AlarmHour = (alarm->AlarmHour-1) % 24;
  4912.                     displayReminderTime( hWnd, EditItem );
  4913.                     return 0;
  4914.                     }
  4915.             //------------------------------------------------------------------
  4916.             //------------------------------------------------------------------
  4917.                 case DID_OK:  {
  4918.                     if (alarm->options & SCHEDULE_LAUNCHAPP)
  4919.                         alarm->options = SCHEDULE_LAUNCHAPP;
  4920.                     else {
  4921.                         alarm->options = 0;
  4922.                         WinQueryDlgItemText( hWnd, REMINDER,
  4923.                                              MAXACTIONSTRINGLENGTH,
  4924.                                              (PSZ)alarm->ActionToDo );
  4925.                         }
  4926.  
  4927.                 if (WinQueryButtonCheckstate( hWnd, EVERYHOUR ))
  4928.                     alarm->options += SCHEDULE_EVERYHOUR;
  4929.                 else if (WinQueryButtonCheckstate( hWnd, EVERYDAY ))
  4930.                     alarm->options += SCHEDULE_EVERYDAY;
  4931.                 else if (WinQueryButtonCheckstate( hWnd, EVERYWEEK ))
  4932.                     alarm->options += SCHEDULE_EVERYWEEK;
  4933.                 else if (WinQueryButtonCheckstate( hWnd, EVERYMONTH ))
  4934.                     alarm->options += SCHEDULE_EVERYMONTH;
  4935.                 else if (WinQueryButtonCheckstate( hWnd, EVERYYEAR ))
  4936.                     alarm->options += SCHEDULE_EVERYYEAR;
  4937.  
  4938.                 if (WinQueryButtonCheckstate( hWnd, PLAYSOUND ))
  4939.                     alarm->options += SCHEDULE_USEWAVFILE;
  4940.                 if (WinQueryButtonCheckstate( hWnd, SOUNDONLY ))
  4941.                     alarm->options += SCHEDULE_SOUNDONLY;
  4942.  
  4943.                 WinQueryDlgItemText( hWnd, SOUNDFILE,
  4944.                                      MAXACTIONSTRINGLENGTH,
  4945.                                      (PSZ)alarm->ReminderWAV );
  4946.  
  4947.                 WinDismissDlg( hWnd, TRUE );
  4948.                 return 0;
  4949.                 }
  4950.                 default:
  4951.                     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4952.             }
  4953.         }
  4954.         //----------------------------------------------------------------------
  4955.         // if nothing further we want to intercept, pass message onto system
  4956.         //----------------------------------------------------------------------
  4957.         default:
  4958.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4959.  
  4960.     }
  4961. }
  4962.  
  4963.  
  4964. ////////////////////////////////////////////////////////////////////////////////
  4965. ////////////////////////////////////////////////////////////////////////////////
  4966. MRESULT EXPENTRY reminderNoteProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  4967. {
  4968.    switch( msg )
  4969.     {
  4970.         //----------------------------------------------------------------------
  4971.         //----------------------------------------------------------------------
  4972.         case WM_TIMER: {
  4973.             ringChime( currentReminderWavFile );
  4974.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4975.             }
  4976.         //----------------------------------------------------------------------
  4977.         // when the dialog is being initialized, center it on desktop
  4978.         //----------------------------------------------------------------------
  4979.         case WM_INITDLG: {
  4980.             SWP swp;
  4981.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  4982.             WinSetWindowPos( hWnd, (HWND)0,
  4983.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  4984.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  4985.                              0, 0, SWP_MOVE);
  4986.             noteTimerNumber = WinStartTimer( hab, hWnd, TIMERID+1, (LONG)repeatTime*1000 );
  4987.             numberOfAlarms = numAlarms;
  4988.             numAlarms = 0;
  4989.             if (mp2 != 0)
  4990.                 WinSetDlgItemText( hWnd, REMINDER, (CHAR*)LONGFROMMP( mp2 ) );
  4991.             WinPostMsg( hWnd, WM_TIMER, mp1, mp2 );
  4992.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  4993.             }
  4994.         //----------------------------------------------------------------------
  4995.         // if we receive any system message, dismiss the dialog box
  4996.         //----------------------------------------------------------------------
  4997.         case WM_COMMAND:
  4998.         {
  4999.             USHORT command = SHORT1FROMMP(mp1);
  5000.  
  5001.             switch(command) {
  5002.             //------------------------------------------------------------------
  5003.             //------------------------------------------------------------------
  5004.             case DID_OK: {
  5005.                 WinStopTimer( hab, TIMERID+1, noteTimerNumber );
  5006.                 WinDismissDlg( hWnd, TRUE );
  5007.                 numAlarms = numberOfAlarms;
  5008.                 oldItemName[0] = FALSE;
  5009.                 return 0;
  5010.                 }
  5011.             //------------------------------------------------------------------
  5012.             //------------------------------------------------------------------
  5013.             case SNOOZE: {
  5014.                 ALARMS* alarm = alarmPtr[0];
  5015.                 struct tm *time_now;
  5016.                 time_t currentTime;
  5017.  
  5018.                 WinStopTimer( hab, TIMERID+1, noteTimerNumber );
  5019.  
  5020.                 tzset();
  5021.                 time(¤tTime);
  5022.                 time_now = localtime( ¤tTime );
  5023.                 alarm->AlarmDay = time_now->tm_mday-1;
  5024.                 alarm->AlarmMonth = time_now->tm_mon;
  5025.                 alarm->AlarmYear = time_now->tm_year;
  5026.                 alarm->AlarmHour = time_now->tm_hour;
  5027.                 alarm->AlarmMinute = time_now->tm_min + 9;
  5028.  
  5029.                 validateTimeEntry();
  5030.                 sortTimeEntries( numberOfAlarms );
  5031.                 WinDismissDlg( hWnd, TRUE );
  5032.                 numAlarms = numberOfAlarms;
  5033.                 return 0;
  5034.                 }
  5035.             //------------------------------------------------------------------
  5036.             //------------------------------------------------------------------
  5037.             case REVISE: {
  5038.                 WinStopTimer( hab, TIMERID+1, noteTimerNumber );
  5039.                 reviseScheduledItem( 0 );
  5040.                 validateTimeEntry();
  5041.                 sortTimeEntries( numberOfAlarms );
  5042.                 WinDismissDlg( hWnd, TRUE );
  5043.                 numAlarms = numberOfAlarms;
  5044.                 return 0;
  5045.                 }
  5046.             //------------------------------------------------------------------
  5047.             //------------------------------------------------------------------
  5048.             case ERASE: {
  5049.                 WinStopTimer( hab, TIMERID+1, noteTimerNumber );
  5050.                 if (WinMessageBox( HWND_DESKTOP, hwndFrame,
  5051.                                    MSG61,
  5052.                                    MSG62, 0,
  5053.                                    MB_MOVEABLE|MB_ICONQUESTION|MB_YESNO)==MBID_YES) {
  5054.                     delete alarmPtr[ 0 ];
  5055.                     for (short i=1; i<MAXALARMS; i++)
  5056.                         alarmPtr[ i-1 ] = alarmPtr[ i ];
  5057.                     WinDismissDlg( hWnd, TRUE );
  5058.                     numAlarms = numberOfAlarms-1;
  5059.                     }
  5060.                 noteTimerNumber = WinStartTimer( hab, hWnd, TIMERID+1, (LONG)repeatTime*1000 );
  5061.                 return 0;
  5062.                 }
  5063.             //------------------------------------------------------------------
  5064.             //------------------------------------------------------------------
  5065.             default:
  5066.                 return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5067.             }
  5068.         }
  5069.         //----------------------------------------------------------------------
  5070.         // if nothing further we want to intercept, pass message onto system
  5071.         //----------------------------------------------------------------------
  5072.         default:
  5073.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5074.     }
  5075. }
  5076.  
  5077.  
  5078. ////////////////////////////////////////////////////////////////////////////////
  5079. ////////////////////////////////////////////////////////////////////////////////
  5080. MRESULT EXPENTRY LaunchItemProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  5081. {
  5082.    ALARMS* alarm = alarmPtr[EditItem];
  5083.  
  5084.    switch( msg )
  5085.     {
  5086.         //----------------------------------------------------------------------
  5087.         // when the dialog is being initialized, center it on desktop
  5088.         //----------------------------------------------------------------------
  5089.         case WM_INITDLG: {
  5090.             SHORT i,j;
  5091.             CHAR temp[MAXACTIONSTRINGLENGTH+5];
  5092.             SWP swp;
  5093.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  5094.             WinSetWindowPos( hWnd, (HWND)0,
  5095.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  5096.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  5097.                              0, 0, SWP_MOVE);
  5098.  
  5099.             oldAction[LAUNCHED] = alarm->options & SCHEDULE_LAUNCHAPP;
  5100.             WinSendDlgItemMsg( hWnd, CURITEMLIST, LM_DELETEALL, 0, 0);
  5101.             temp[0] = ' ';
  5102.             temp[1] = ' ';
  5103.             temp[2] = '-';
  5104.             temp[3] = ' ';
  5105.             for (i=0; i<NumMenus; i++) {
  5106.                 WinSendDlgItemMsg( hWnd, CURITEMLIST, LM_INSERTITEM, MPFROMSHORT( LIT_END ), MenuName[i] );
  5107.                 for (j=0; j<NumItems[i]; j++)
  5108.                    if (Menus[i][j]->ItemName[0] != '\0') {
  5109.                         temp[4] = '\0';
  5110.                         strcat(temp, Menus[i][j]->ItemName);
  5111.                         WinSendDlgItemMsg( hWnd, CURITEMLIST, LM_INSERTITEM, MPFROMSHORT( LIT_END ), temp );
  5112.                         }
  5113.                 }
  5114.  
  5115.             // if they had requested to launch an application previously
  5116.             // restore their choice in the dialog box
  5117.             WinCheckButton( hWnd, LAUNCHITEM, FALSE );
  5118.             if (oldAction[LAUNCHED]) {
  5119.                 SHORT item, index;
  5120.                 WinCheckButton( hWnd, LAUNCHITEM, TRUE );
  5121.  
  5122.                 item = 0;
  5123.                 index = alarm->ActionToDo[0];
  5124.                 if (index > 0) {
  5125.                     for (i=0; i<index; i++) {
  5126.                         item++;
  5127.                         for (j=0; j<NumItems[i]; j++)
  5128.                             if (Menus[i][j]->ItemName[0] != '\0')
  5129.                                 item++;
  5130.                         }
  5131.                     }
  5132.  
  5133.                 item += alarm->ActionToDo[1]+1;
  5134.  
  5135.                 for (j=0; j<alarm->ActionToDo[1]; j++)
  5136.                     if (Menus[index][j]->ItemName[0] == '\0')
  5137.                         item--;
  5138.  
  5139.                 WinSendDlgItemMsg( hWnd, CURITEMLIST, LM_SELECTITEM,
  5140.                                    MPFROM2SHORT( item, 0 ),
  5141.                                    MPFROM2SHORT( TRUE, 0 ) );
  5142.                 }
  5143.  
  5144.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5145.             }
  5146.         //----------------------------------------------------------------------
  5147.         //----------------------------------------------------------------------
  5148.         case WM_CONTROL:
  5149.         {
  5150.             if (SHORT1FROMMP(mp1)==CURITEMLIST) {
  5151.                 if (SHORT2FROMMP(mp1)==LN_ENTER) {
  5152.                     WinCheckButton( hWnd, LAUNCHITEM, TRUE );
  5153.                     WinSendMsg( hWnd, WM_COMMAND, MPFROMSHORT(DID_OK), 0 );
  5154.                     }
  5155.                 if (SHORT2FROMMP(mp1)==LN_SELECT)
  5156.                     WinCheckButton( hWnd, LAUNCHITEM, TRUE );
  5157.                 }
  5158.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5159.         }
  5160.         //----------------------------------------------------------------------
  5161.         //----------------------------------------------------------------------
  5162.         case WM_COMMAND:
  5163.         {
  5164.             if (SHORT1FROMMP(mp1)==DID_OK) {
  5165.                 SHORT itemSelected = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURITEMLIST,
  5166.                                                                       LM_QUERYSELECTION,
  5167.                                                                       MPFROM2SHORT( LIT_FIRST, 0 ),
  5168.                                                                       0 ) );
  5169.                 if (WinQueryButtonCheckstate( hWnd, LAUNCHITEM )) {
  5170.                         short i,j;
  5171.                         char temp[MAXPATH];
  5172.  
  5173.                         WinSendDlgItemMsg( hWnd, CURITEMLIST,
  5174.                                                LM_QUERYITEMTEXT,
  5175.                                                MPFROM2SHORT( itemSelected, sizeof(temp) ),
  5176.                                                (PSZ)temp );
  5177.  
  5178.                         if (strncmp(temp, "  - ", 4) != 0) {
  5179.                             WinMessageBox( HWND_DESKTOP, hwndFrame,
  5180.                                            MSG63,
  5181.                                            MSG64, 0,
  5182.                                            MB_MOVEABLE|MB_ERROR|MB_OK);
  5183.                             return 0;
  5184.                             }
  5185.  
  5186.                         if ( !oldAction[LAUNCHED] )
  5187.                             alarm->options += SCHEDULE_LAUNCHAPP;
  5188.  
  5189.                         for (i=0; i<NumMenus; i++)
  5190.                             for (j=0; j<NumItems[i]; j++)
  5191.                                 if (strcmp( temp+4, Menus[i][j]->ItemName ) == 0) {
  5192.                                     alarm->ActionToDo[0] = i;
  5193.                                     alarm->ActionToDo[1] = j;
  5194.                                     }
  5195.                     }
  5196.                 else {
  5197.                     if ( oldAction[LAUNCHED] ) {
  5198.                         alarm->options -= SCHEDULE_LAUNCHAPP;
  5199.                         alarm->ActionToDo[0] = 0;
  5200.                         }
  5201.                     }
  5202.                 WinDismissDlg( hWnd, TRUE );
  5203.                 return 0;
  5204.                 }
  5205.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5206.         }
  5207.         //----------------------------------------------------------------------
  5208.         // if nothing further we want to intercept, pass message onto system
  5209.         //----------------------------------------------------------------------
  5210.         default:
  5211.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5212.     }
  5213. }
  5214.  
  5215.  
  5216. ////////////////////////////////////////////////////////////////////////////////
  5217. ////////////////////////////////////////////////////////////////////////////////
  5218. MRESULT EXPENTRY popUpOptionsProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  5219. {
  5220.    switch( msg )
  5221.     {
  5222.         //----------------------------------------------------------------------
  5223.         // when the dialog is being initialized, center it on desktop
  5224.         //----------------------------------------------------------------------
  5225.         case WM_INITDLG: {
  5226.             SWP swp;
  5227.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  5228.             WinSetWindowPos( hWnd, (HWND)0,
  5229.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  5230.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  5231.                              0, 0, SWP_MOVE);
  5232.             WinCheckButton( hWnd, HIDE_FILEBAR, (hideFileBar==TRUE) );
  5233.             WinCheckButton( hWnd, ENABLE_POPUP, (allowPopUpMenu==TRUE) );
  5234.             WinEnableControl( hWnd, REMINDER, FALSE );
  5235.  
  5236.             switch( popUpMessageID ) {
  5237.                 case WM_CHORD:
  5238.                     WinCheckButton( hWnd, MOUSE_CHORD, TRUE );
  5239.                     break;
  5240.                 case WM_BUTTON1CLICK:
  5241.                     WinCheckButton( hWnd, MOUSEBUTTON1, TRUE );
  5242.                     break;
  5243.                 case WM_BUTTON2CLICK:
  5244.                     WinCheckButton( hWnd, MOUSEBUTTON2, TRUE );
  5245.                     break;
  5246.                 case WM_BUTTON3CLICK:
  5247.                     WinCheckButton( hWnd, MOUSEBUTTON3, TRUE );
  5248.                     break;
  5249.                 case WM_BUTTON1DBLCLK:
  5250.                     WinCheckButton( hWnd, MOUSEDCLICK1, TRUE );
  5251.                     break;
  5252.                 case WM_BUTTON2DBLCLK:
  5253.                     WinCheckButton( hWnd, MOUSEDCLICK2, TRUE );
  5254.                     break;
  5255.                 case WM_BUTTON3DBLCLK:
  5256.                     WinCheckButton( hWnd, MOUSEDCLICK3, TRUE );
  5257.                     break;
  5258.                 }
  5259.             if (hideFileBar)
  5260.                 WinEnableControl( hWnd, ENABLE_POPUP, FALSE );
  5261.             else
  5262.                 WinEnableControl( hWnd, ENABLE_POPUP, TRUE );
  5263.  
  5264.             if (allowPopUpMenu)
  5265.                 WinEnableControl( hWnd, HIDE_FILEBAR, TRUE );
  5266.             else
  5267.                 WinEnableControl( hWnd, HIDE_FILEBAR, FALSE );
  5268.  
  5269.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5270.             }
  5271.         //----------------------------------------------------------------------
  5272.         // if we receive any system message, dismiss the dialog box
  5273.         //----------------------------------------------------------------------
  5274.         case WM_CONTROL:
  5275.         {
  5276.             if (WinQueryButtonCheckstate( hWnd, HIDE_FILEBAR ))
  5277.                 WinEnableControl( hWnd, ENABLE_POPUP, FALSE );
  5278.             else
  5279.                 WinEnableControl( hWnd, ENABLE_POPUP, TRUE );
  5280.  
  5281.             if (WinQueryButtonCheckstate( hWnd, ENABLE_POPUP ))
  5282.                 WinEnableControl( hWnd, HIDE_FILEBAR, TRUE );
  5283.             else
  5284.                 WinEnableControl( hWnd, HIDE_FILEBAR, FALSE );
  5285.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5286.         }
  5287.  
  5288.         //----------------------------------------------------------------------
  5289.         // if we receive any system message, dismiss the dialog box
  5290.         //----------------------------------------------------------------------
  5291.         case WM_COMMAND:
  5292.         {
  5293.             popUpMessageID = WM_BUTTON3CLICK;
  5294.             if (WinQueryButtonCheckstate( hWnd, MOUSE_CHORD ))
  5295.                 popUpMessageID = WM_CHORD;
  5296.             else if (WinQueryButtonCheckstate( hWnd, MOUSEBUTTON1 ))
  5297.                 popUpMessageID = WM_BUTTON1CLICK;
  5298.             else if (WinQueryButtonCheckstate( hWnd, MOUSEBUTTON2 ))
  5299.                 popUpMessageID = WM_BUTTON2CLICK;
  5300.             else if (WinQueryButtonCheckstate( hWnd, MOUSEDCLICK1 ))
  5301.                 popUpMessageID = WM_BUTTON1DBLCLK;
  5302.             else if (WinQueryButtonCheckstate( hWnd, MOUSEDCLICK2 ))
  5303.                 popUpMessageID = WM_BUTTON2DBLCLK;
  5304.             else if (WinQueryButtonCheckstate( hWnd, MOUSEDCLICK3 ))
  5305.                 popUpMessageID = WM_BUTTON3DBLCLK;
  5306.             hideFileBar = WinQueryButtonCheckstate( hWnd, HIDE_FILEBAR );
  5307.             allowPopUpMenu = WinQueryButtonCheckstate( hWnd, ENABLE_POPUP );
  5308.             setFileBarScreen( (BOOL)(BarPosition==AT_TOP), MenuHeight, (interceptMsg==TRUE),
  5309.                               allowPopUpMenu, popUpMessageID );
  5310.             if (hideFileBar)
  5311.                 WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_HIDE);
  5312.             else
  5313.                 WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_SHOW);
  5314.             WinDismissDlg( hWnd, TRUE );
  5315.             return 0;
  5316.         }
  5317.         //----------------------------------------------------------------------
  5318.         // if nothing further we want to intercept, pass message onto system
  5319.         //----------------------------------------------------------------------
  5320.         default:
  5321.             break;
  5322.     }
  5323.     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5324. }
  5325.  
  5326.  
  5327. ////////////////////////////////////////////////////////////////////////////////
  5328. ////////////////////////////////////////////////////////////////////////////////
  5329. VOID changePassword( CHAR* password )
  5330. {
  5331.     char mesg[64];
  5332.     char newpwd[PASSWORDLEN+1];
  5333.  
  5334.     sprintf( parameterTitle, MSG65 );
  5335.     sprintf( mesg, MSG66 );
  5336.     ParameterTextPtr = mesg;
  5337.     oldProgType = PASSWORDLEN;
  5338.     (VOID*)WinDlgBox(HWND_DESKTOP,
  5339.                      hwndFrame,
  5340.                      (PFNWP)EnterParamProc,
  5341.                      0,
  5342.                      PASSWORDENTRY,
  5343.                      (PVOID)NULL);
  5344.     strcpy( newpwd, variableText );
  5345.  
  5346.     sprintf( mesg, MSG67 );
  5347.     ParameterTextPtr = mesg;
  5348.     (VOID*)WinDlgBox(HWND_DESKTOP,
  5349.                      hwndFrame,
  5350.                      (PFNWP)EnterParamProc,
  5351.                      0,
  5352.                      PASSWORDENTRY,
  5353.                      (PVOID)NULL);
  5354.  
  5355.     if (strcmp( newpwd, variableText ) == 0) {
  5356.         strcpy( password, newpwd );
  5357.         WinMessageBox( HWND_DESKTOP, hwndFrame,
  5358.                        MSG68,
  5359.                        MSG69, 0,
  5360.                        MB_MOVEABLE|MB_ICONEXCLAMATION|MB_OK);
  5361.         }
  5362.     else
  5363.         WinMessageBox( HWND_DESKTOP, hwndFrame,
  5364.                        MSG70,
  5365.                        MSG69, 0,
  5366.                        MB_MOVEABLE|MB_ERROR|MB_OK);
  5367. }
  5368.  
  5369. ////////////////////////////////////////////////////////////////////////////////
  5370. ////////////////////////////////////////////////////////////////////////////////
  5371. MRESULT EXPENTRY globalPasswordProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  5372. {
  5373.    switch( msg )
  5374.     {
  5375.         //----------------------------------------------------------------------
  5376.         // when the dialog is being initialized, center it on desktop
  5377.         //----------------------------------------------------------------------
  5378.         case WM_INITDLG: {
  5379.             SWP swp;
  5380.             WinQueryWindowPos( hWnd, (PSWP)&swp);
  5381.             WinSetWindowPos( hWnd, (HWND)0,
  5382.                              ((SHORT)((ScreenSizeX-swp.cx)/2)),
  5383.                              ((SHORT)((ScreenSizeY-swp.cy)/2)),
  5384.                              0, 0, SWP_MOVE);
  5385.  
  5386.             WinCheckButton( hWnd, USEPASSWORD, (globalProtection==YES) );
  5387.             tmpBuffer[0] = globalProtection;
  5388.  
  5389.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5390.             }
  5391.  
  5392.         //----------------------------------------------------------------------
  5393.         // if we receive any system message, dismiss the dialog box
  5394.         //----------------------------------------------------------------------
  5395.         case WM_COMMAND:
  5396.         {
  5397.             if (SHORT1FROMMP(mp1)==DID_OK) {
  5398.                 if (WinQueryButtonCheckstate( hWnd, USEPASSWORD ))
  5399.                     globalProtection=YES;
  5400.                 else
  5401.                     globalProtection=NO;
  5402.                 WinDismissDlg( hWnd, TRUE );
  5403.                 }
  5404.             else if (SHORT1FROMMP(mp1)==CHANGEPASSWORD) {
  5405.                 if ((globalProtection==YES) && ( !checkAgainstPassWord( password ) ))
  5406.                     return 0;
  5407.                 changePassword( password );
  5408.                 return 0;
  5409.                 }
  5410.             return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5411.         }
  5412.         //----------------------------------------------------------------------
  5413.         // if nothing further we want to intercept, pass message onto system
  5414.         //----------------------------------------------------------------------
  5415.         default:
  5416.             break;
  5417.     }
  5418.     return WinDefDlgProc( hWnd, msg, mp1, mp2 );
  5419. }
  5420.  
  5421.  
  5422.  
  5423.  
  5424.